These forums are now closed and remain for historical purposes.
None of the content applies to the new version 3. For support, get in touch via our contact form.
Forums › Forums › Search & Filter Pro › Custom post type not showing in "post type" search form UI checkboxes
Hi Thomas
So I’ve found a better way to do this (that can be search form specific).
The code in full (so remove everything else we’ve added:
function filter_input_object_radio($input_object, $sfid){
if(($input_object['name']!='_sf_post_type')||($input_object['type']!='radio'))
{
return $input_object;
}
if(isset($input_object['options'])){
//remove the first option from the array
$removed_option = array_shift($input_object['options']);
}
//now set the default value in the field
//make sure we only modify a field belonging to a specific Search Form, by ID
if($sfid==15485){ //replace 15485 with your search form ID
//make sure the field is not set
if(!isset($_GET['post_types'])){
//then set it to "post"
$input_object['defaults'] = array("post");
}
}
return $input_object;
}
add_filter('sf_input_object_pre', 'filter_input_object_radio', 10, 2);
function set_default_post_type_query( $query_args, $sfid ) {
//if search form ID = 225, the do something with this query
if($sfid==15485) //replace 15485 with your search form ID
{
//modify $query_args here before returning it
if(!isset($_GET['post_types'])){
$query_args['post_type'] = 'post';
}
}
return $query_args;
}
add_filter( 'sf_edit_query_args', 'set_default_post_type_query', 20, 2 );
The only thing you have to replace is the search form ID of 15485
(there are 2 instances of this) – swap this out to match the ID of the search form on the homepage and it should work 🙂
Best
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
We also use cookies to store items in your cart as well as allowing your to login on the site.
You can adjust all of your cookie settings by navigating the tabs on the left hand side.
By continuing to use this site, you also agree to our Privacy Policy.
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
*Other cookies used for logging in and cart functions will only be used when you use those features and cannot be disabled.
If you disable these cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!
More information about our Cookie Policy