Search results pulling in unchecked post types

Forums › Forums › Search & Filter Pro › Search results pulling in unchecked post types

Viewing 6 posts – 1 through 6 (of 6 total)
  • Anonymous
    #20221

    I setup SFP for a custom post type on my site. I only have the CPT checked for post types to search.
    CPT

    On the initial results page, only the CPT posts show in the results. However, when I do a search for a word, such as “Basic” it pulls in the CPT posts (expected), as well as the standard posts (like what’s on the home page). I know I can exclude by ID but that’s going to get really cumbersome.

    Any thoughts as to what may be wrong?

    You can test here:
    http://hotsguides.com/guides/

    Ross Moderator
    #20223

    Hey there

    That does sound strange – what it sounds like is going on is you have some code that is adding post types to search results.

    Typically, when a user enters a search term, the variable is_search gets set to true. It sounds like something is acting on that so that it is adding post types to the query itself.

    This sounds like it might be some custom code in your functions.php or something from another plugin.

    To test the theory, under the “advanced” tab, you could try setting “force is_search to always be true” – I think then no matter whether there is a search term or not, you will get unwanted post types?

    Thanks

    Anonymous
    #20280

    So I should check that if I want ALL results? I already get all results though. 🙁

    I’ll check in functions to see if something weird is being added. TY

    Anonymous
    #20281

    Ah yes, I have this:

    function cpt_search( $query ) {
    	
        if ( $query->is_search ) {
    	$query->set( 'post_type', array( 'post', 'guides' ) );
        }
        
        return $query;
        
    }

    Because whenever I searched for a guide under the normal site search, the results were not being pulled in.

    Ross Moderator
    #20289

    Ah great, so you just need to remove this – if you need to keep it take a look at the code for detecting if its and S&F form (this is changing in the next update though so beware)

    So you would need to do something like:

    function cpt_search( $query ) {
    	
        if ( $query->is_search ) {
            
            global $sf_form_data;
            
            if (!$sf_form_data->is_valid_form())
            {//make sure this is not a S&F form
    
    	    $query->set( 'post_type', array( 'post', 'guides' ) );
            }
        }
        
        return $query;
    }
    Anonymous
    #20314

    You are magic! That worked perfectly. Thank you! 🙂

Viewing 6 posts – 1 through 6 (of 6 total)
Search & Filter Support
Privacy Overview

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.