Skip to content

Instantly share code, notes, and snippets.

@ckpicker
Created August 5, 2014 19:40
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 ckpicker/b247169a4f124fa6ea7c to your computer and use it in GitHub Desktop.
Save ckpicker/b247169a4f124fa6ea7c to your computer and use it in GitHub Desktop.
Events Calendar 3.7 // Query Events by City & Country
<?php
//Retrieve venues that match query criteria
$args = array(
'nopaging' => true,
'post_type'=>'tribe_venue',
//Only query venues in specific locations
'meta_query' => array(
'relation' => 'AND',
//Specific City
array(
'key' => '_VenueCity',
'value' => array( 'Chicago'),
'compare' => 'IN',
),
//Specific Country
array(
'key' => '_VenueCountry',
'value' => array( 'United States'),
'compare' => 'IN',
)
)
);
$country_venue = get_posts( $args );
$venue_ids = array();
//Loops through venues and add ID to array
foreach( $country_venue as $post ) {
setup_postdata($post);
//Get ID of matching Venue
$venue_ids[] = get_the_id();
}
wp_reset_postdata();
//If Venue IDs were found, then query events
if( !empty( $venue_ids ) ) {
//Retrieve Events with matching Venue IDs
$event_args = array(
'eventDisplay' => 'all',
'posts_per_page'=> 10,
//Only query venues in specific countries
'meta_query' => array(
array(
'key' => '_EventVenueID',
'value' => $venue_ids,
'compare' => 'IN',
)
)
);
$country_events = tribe_get_events( $event_args );
//Loops through events and display
foreach( $country_events as $post ) {
setup_postdata($post);
echo '<h2>' . get_the_title() . '</h2>';
}
wp_reset_postdata();
}
?>
@polack45
Copy link

Hi,

Thanks of lot for you're code.
It's very help me !
And i would like to add 'taxonomy' =>tribe_event_cats
where can i take it's ?
Sorry for my english...i'm french
Thanks for you're help.
See you bye
Stéphanie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment