Last active
August 29, 2015 14:23
-
-
Save slimndap/6b9e1a31ec56c0f302a5 to your computer and use it in GitHub Desktop.
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/.
This file contains 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
/** | |
* 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