Created
August 5, 2014 19:40
-
-
Save ckpicker/b247169a4f124fa6ea7c to your computer and use it in GitHub Desktop.
Events Calendar 3.7 // Query Events by City & Country
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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