Forums › Forums › Search & Filter Pro › Search results pulling in unchecked post types
Tagged: custom post type, results
- This topic has 5 replies, 2 voices, and was last updated 9 years, 6 months ago by Anonymous.
-
Anonymous(Private) June 24, 2015 at 11:49 pm #20221
I setup SFP for a custom post type on my site. I only have the CPT checked for post types to search.
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(Private) June 25, 2015 at 2:02 am #20223Hey 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(Private) June 25, 2015 at 5:28 pm #20281Ah 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(Private) June 25, 2015 at 6:07 pm #20289Ah 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; }
-
AuthorPosts