Just woo products on search results page

Is there a way to show just products in the results page without affecting native features like pagination.

I create next code to make a test:
function JustProductFilter($query) {
if ($query->is_search && !is:admin() ) {
$query->set(‘post_type’, ‘‘product’);
}
return $query;
}
add_filter(‘pre_get_posts’,‘JustProductFilter’);

Above code is affecting the PRO builder too, this was an unexpected behavior. Please, I know you don’t support custom code, I hope you understand im asking for your solution, not mine.

I solved it temporally by adding also !current_user_can(‘administrator’), this last part of the code solve the ProBuilder conflict but within having a wrong view in the builder and front-page while im signed in. Hope to here from you soon. Thank you

Hi @armandogomez,

Glad that you are able to solve it. The correct condition to match is !is_admin() so the line of code will look like the following.

if ($query->is_search && !is_admin() ) {

Thanks

I made a mistake by writing !is:admin in the ticket but my real code has!is_admin, the problem persist

Hi @armandogomez,

I have checked your code thoroughly and didn’t find any problem in it and it worked with the is_admin() function too. There might be something else that is the reason behind your issue, but unfortunately, we don’t offer any investigation on custom coding or related issues.

Thanks

The problem is that I solve the query for frontend but on PRO is not working.

Is there any other way, probably with query builder or other feature inside PRO which I can use to show up just product in search results page without affecting the pagination?

Hi @armandogomez,

I have checked the code in Pro and found it was working. The code is not dependent on any specific theme and will work as it is with every theme. So there might be something else which is the reason behind your issue.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.