Skip Navigation

[Resolved] Text search returns wrong post type in results

This support ticket is created 4 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 17 replies, has 3 voices.

Last updated by davidL-7 4 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1545897

Thanks Nigel,

While you're taking a look, I wanted to return to a question that I asked Waqar and didn't get a complete answer to. I asked:

When Toolset shows the custom search results on a separate page, is everything determined by the query string? In Test 6, searching on the word "camp" (no quotes), the query string is:

wpv_post_search=camp
&wpv-resource-hub-category=0
&wpv-wpcf-resource-type=
&wpv_filter_submit=Search+the+Resource+Hub

I don't see anything in the query string that defines the post type, so I'm wondering if that gets designated via a session variable, or some other way?

Waqar replied:

As for your question regarding query string, Toolset relies on them for the front-end filters but based on the view's settings, all of the query parameters may not always get exposed in the query string.

So I think we clarified that the instruction regarding which type(s) of post to include in the query doesn't get designated in the query string but Waqar didn't indicate where/how Toolset does this. The reason I ask is that I may need to go through this custom theme line by line to determine where the issue is, and I'm looking for clues as to what would interfere with Toolset's functioning in this regard. For example, if Toolset writes a session variable to communicate from the search page to the results page, then that would tell me I need to look at the session handling. Can you tell me where/how that post type query gets defined?

Thanks!
David

#1546533

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

The post type is determined by the View settings, it's invariant, when Views constructs the query it takes the value for the post type from the View settings, it doesn't need to be "passed" the post type in any sense.

So if your View is returning results from a different post type that would indicate that something is interfering in the query being created by Views.

You can think of Views as a visual wrapper for the main WordPress WP_Query class which is used (by functions such as get_posts) to retrieve posts from the database.

If I had to guess I would say something is likely using the pre_get_posts hook to modify queries, and it isn't "watertight", it is indiscriminantly altering any query rather than targeted queries, so it's affecting the query that Views builds when it should have nothing to do with it.

That's a guess, but one of the more plausible explanations.

#1547425

My issue is resolved now. Thank you!

I began combing through the custom theme, and found this block of code in the theme's functions.php file:

function fb_search_filter($query) {
	if ( !$query->is_admin && $query->is_search) {
	$query->set('post_type', array('resource', 'training_videos', 'page', 'post') );
	}
	return $query;
	}
	add_filter( 'pre_get_posts', 'fb_search_filter' );

That was the culprit. As soon as I commented that out, the text search returns the post type I designated in my view (which was a new post type I had created that was not in that array).

Thanks again for letting me bounce this off of you,
David

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.