- function events_featured ( $atts ) {
- // - define arguments -
- extract(shortcode_atts(array(
- 'limit' => '100', // # of events to show
- 'group' => ' ',
- ), $atts));
- // ===== OUTPUT FUNCTION =====
- ob_start();
- // ===== LOOP: FULL EVENTS SECTION =====
- // - hide events that are older than 6am today (because some parties go past your bedtime) -
- $today6am = strtotime('today 6:00') + ( get_option( 'gmt_offset' ) * 3600 );
- // - query -
- global $wpdb;
- $querystr = "
- SELECT *
- FROM $wpdb->postmeta metastart, $wpdb->postmeta metaend, $wpdb->posts
- LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
- LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
- LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
- LEFT JOIN $wpdb->terms ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
- WHERE ($wpdb->posts.ID = metastart.post_id AND $wpdb->posts.ID = metaend.post_id)
- AND $wpdb->term_taxonomy.taxonomy = 'tf_eventcategory'
- AND $wpdb->terms.name = '$group'
- AND (metaend.meta_key = 'tf_events_enddate' AND metaend.meta_value > $today6am )
- AND metastart.meta_key = 'tf_events_enddate'
- AND $wpdb->posts.post_type = 'tf_events'
- AND $wpdb->posts.post_status = 'publish'
- ORDER BY metastart.meta_value ASC LIMIT $limit
- ";
- $events = $wpdb->get_results($querystr, OBJECT);
- // - declare fresh day -
- $daycheck = null;
- // - loop -
- if ($events):
- global $post;
- foreach ($events as $post):
- setup_postdata($post);
- // - custom variables -
- $custom = get_post_custom(get_the_ID());
- $sd = $custom["tf_events_startdate"][0];
- $ed = $custom["tf_events_enddate"][0];
- // - determine if it's a new day -
- $longdate = date("l, F j, Y", $sd);
- if ($daycheck == null) { echo '<h2 class="events-featured">' . $longdate . '</h2>'; }
- if ($daycheck != $longdate && $daycheck != null) { echo '<h2 class="events-featured">' . $longdate . '</h2>'; }
- // - local time format -
- $time_format = get_option('time_format');
- $stime = date($time_format, $sd);
- $etime = date($time_format, $ed);
- $postlinkid = get_the_ID();
- // - output - ?>
- <div class="events-featured">
- <div class="text">
- <div class="title">
- <div class="time"><?php echo $stime . ' - ' . $etime; ?></div>
- <div class="eventtext"><a href="<?php echo get_permalink($postlinkid); ?>"><?php the_title(); ?></a></div>
- </div>
- </div>
- <div class="desc"><?php if (strlen($post->post_content) > 150) { echo substr($post->post_content, 0, 150) . '...'; } else { echo $post->post_content; } ?></div>
- </div>
- <?php
- // - fill daycheck with the current day -
- $daycheck = $longdate;
- endforeach;
- else :
- endif;
- // ===== RETURN: FULL EVENTS SECTION =====
- $output = ob_get_contents();
- ob_end_clean();
- return $output;
- }
- add_shortcode('events-featured', 'events_featured'); // You can now call onto this shortcode with [events-featured limit='20']