Last active
August 27, 2021 12:53
-
-
Save ramshengale/661b1360434698112a30f399f8279cbc to your computer and use it in GitHub Desktop.
Show Venue as filter in Search and Filter Pro plugin for The Events Calendar plugin's event post type
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
<?php | |
/* | |
* Add a post meta field in S&F plugin and select _EventVenueID and then put this in functions.php | |
*/ | |
add_filter('sf_input_object_pre', function ($input_object, $sfid) { | |
if ($input_object['name'] == '_sfm__EventVenueID' && $sfid == 1048) { | |
if (! isset($input_object['options'])) { | |
return $input_object; | |
} | |
$new_options = []; | |
$all_venues = get_posts([ | |
'post_type' => 'tribe_venue', | |
'numberposts' => -1 | |
]); | |
if (isset($all_venues)) { | |
foreach ($all_venues as $venue) { | |
// create a new "default" option | |
$new_option = new StdClass(); | |
$new_option->value = $venue->ID; | |
$new_option->label = $venue->post_title; | |
array_push($new_options, $new_option); | |
} | |
} | |
$input_object['options'] = $new_options; | |
} | |
return $input_object; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment