Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Custom post type not showing in "post type" search form UI checkboxes

Viewing 2 posts - 21 through 22 (of 22 total)
  • Ross Moderator
    #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

    Thomas
    #219140

    Works a treat! Many thanks

Viewing 2 posts - 21 through 22 (of 22 total)

The topic ‘Custom post type not showing in "post type" search form UI checkboxes’ is closed to new replies.