Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds venue and city filters to event listings. Eg. [wpt_events venue="Ritz" city="El paso"]. For a full explanation see: http://www.slimndap.com/add-venue-and-city-filters-to-event-listings/.
/**
* Adds venue and city filters to the default options for event listings.
*
* @param array $defaults The current defaults.
* @return array The defaults with venue and city added.
*/
function add_venue_filter_to_events($defaults) {
$defaults['venue'] = false;
$defaults['city'] = false;
return $defaults;
}
add_filter( 'wpt/frontend/shortcode/events/defaults', 'add_venue_filter_to_events', 10 );
add_filter( 'wpt/events/get/defaults', 'add_venue_filter_to_events', 10 );
/**
* Adds venue and city meta_queries to event query args.
*
* @param array $args The current event query args.
* @param array $filters The filters for this listing.
* @return array The new event query args.
*/
function add_venue_filter_events_query($args, $filters) {
if ( $filters['venue'] ) {
$args['meta_query'][] = array(
'key' => 'venue',
'value' => $filters[ 'venue' ],
);
}
if ( $filters['city'] ) {
$args['meta_query'][] = array(
'key' => 'city',
'value' => $filters[ 'city' ],
);
}
return $args;
}
add_filter( 'wpt/events/get/args', 'add_venue_filter_events_query', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment