Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajithrn/3f54177ed3023f618ccb6c77b7ad1af4 to your computer and use it in GitHub Desktop.
Save ajithrn/3f54177ed3023f618ccb6c77b7ad1af4 to your computer and use it in GitHub Desktop.
The Events Calendar - Custom Query Using WP_Query
<?php
$args = array(
'post_status'=>'publish',
'post_type'=>array(TribeEvents::POSTTYPE),
'posts_per_page'=>10,
//order by startdate from newest to oldest
'meta_key'=>'_EventStartDate',
'orderby'=>'_EventStartDate',
'order'=>'DESC',
//required in 3.x
'eventDisplay'=>'custom',
//query events by category
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'featured',
'operator' => 'IN'
),
)
);
$get_posts = null;
$get_posts = new WP_Query();
$get_posts->query($args);
if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a><br />
<?php if (tribe_get_start_date() !== tribe_get_end_date() ) { ?>
<?php echo tribe_get_start_date(); ?> - <?php echo tribe_get_end_date(); ?>
<?php } else { ?>
<?php echo tribe_get_start_date(); ?>
<?php } ?>
<?php the_content(); ?>
<?php
endwhile;
endif;
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment