Forums › Forums › Search & Filter Pro › Custom post type not showing in "post type" search form UI checkboxes
- This topic has 21 replies, 3 voices, and was last updated 7 years ago by
Anonymous.
-
Ross Moderator(Private) August 16, 2019 at 2:05 pm #219135
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
-
AuthorPosts