Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Do we need to filter by event tag?
- */
- if(is_tax('event_tags') ) :
- $tag = strip_tags( get_query_var('event_tags') );
- $querystr = "
- SELECT wposts.*
- FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->terms wterms, $wpdb->term_taxonomy wtax, $wpdb->term_relationships wrels
- WHERE wposts.ID = wpostmeta.post_id
- AND wterms.term_id = wtax.term_id
- AND wtax.term_taxonomy_id = wrels.term_taxonomy_id
- AND wrels.object_id = wposts.ID
- AND wterms.slug = '$tag'
- ";
- else:
- $querystr = "
- SELECT wposts.*
- FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
- WHERE wposts.ID = wpostmeta.post_id";
- endif;
- // Build the rest of the query, i.e. only get events with dates, and order newest first.
- $querystr .= "
- AND wpostmeta.meta_key = 'Date'
- AND STR_TO_DATE(wpostmeta.meta_value,'%m/%d/%Y') >= CURDATE()
- AND wposts.post_status = 'publish'
- AND wposts.post_type = 'events'
- ORDER BY STR_TO_DATE(wpostmeta.meta_value,'%m/%d/%Y') ASC
- LIMIT 20
- ";
- $events = $wpdb->get_results($querystr, OBJECT);
- if ($events):
- echo '<ul>';
- foreach ($events as $post):
- global $post;
- setup_postdata($post);
- // Get a friendlier version of the date.
- $date = get_post_meta($post->ID, 'Date', true);
- $date = date_create($date);
- $date = date_format($date, 'jS F, Y');
- ?>
- <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> - <?php echo $date; ?></li>
- <?php endforeach;
- echo '</ul>';
- endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement