Support Forums

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

This topic is: resolved

This topic contains 21 replies, has 3 voices, and was last updated by  Thomas 1 month ago.

Viewing 10 posts - 1 through 10 (of 22 total)
  • Thomas
    #218238

    Hi,

    I’m using the download monitor plugin to manage and display WP documents and would like to integrate the related custom post type (dlm_downloads) in a post-type based search form. Basically, the form should display items in the post types posts, events and downloads, along with filters for each one.

    My problem is that Download Monitor’s “Downloads” post type shows up just fine under “Search in the following post types” but not under the post type filter.

    Any idea of how this could be fixed?

    Thanks

    Trevor Moderator
    #218248
    This reply has been marked as private.
    Thomas
    #218252
    This reply has been marked as private.
    Trevor Moderator
    #218308
    This reply has been marked as private.
    Ross Moderator
    #218477
    This reply has been marked as private.
    Thomas
    #218667

    Hi both,

    Seems like that was indeed the problem. Thank you Ross for identifying it!

    I have another question. How can I deactivate the “All Post Types” filter?

    I tried with JQuery’s .remove method but it doesn’t seem to affect your plugin.

    Thanks

    Ross Moderator
    #218722

    Hi again

    If you take a look, we have a filter, which will allow you to modify any option in a field (so you will want to remove the first option):
    https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object

    Take a look at the full featured example to get an idea how to move the options around.

    Thanks

    Thomas
    #218732

    Hmm I’m a bit lost.

    What I’m trying to do is not only to remove the all post types filter, but also ensure that one of the selected post types (in my case, press-releases) is selected by default instead in place of the removed filter. I’m not sure how I can use your example to achieve that. Any guidance would be much appreciated.

    Thomas
    #218803

    OK so this is as far as I got:

    function filter_input_object($input_object, $sfid)
    {
    
    	if(($input_object['name']!='_sf_post_type')||($input_object['type']!='radio'))
    	{
    		return $input_object;
    	}
    	
    	foreach($input_object['options'] as $option)
    	{
    		if($option->value=="")
    		{
    			
    		}
    		else if($option->value=="post")
    		{
    			
    		}
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    All I need now is to assign actions for the ‘if’ and ‘elseif’. But I couldn’t find any example. I would like to hide or delete the option with no value and make the one with value ‘post’ preselected.

    Can you help please?

    Ross Moderator
    #218808

    Hi Thomas

    Because we know the first option is the option we want to remove, we can do it a bit easier like this:

    function filter_input_object($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']);
    	}	
    	
    	return $input_object;
    }
    
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);

    Now, I’m guessing that this will work (I didn’t test but it looks correct), however, I think next you want the results to be default fitlered by this option?

    Thanks

Viewing 10 posts - 1 through 10 (of 22 total)

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