Archived topic
Search results products
20 replies · Started by Pedro on February 10, 2019
Hello! I would like for the search results to show only products, not pages or blog articles.
How can I do it? Thank you!
Hi there,
See the first example here:
https://docs.generatepress.com/article/generate_navigation_search_output/
Let me know :)
Hello! And where can I place that code? I'm a novice
Adding PHP: https://docs.generatepress.com/article/adding-php/
We also specified this at the bottom of the articles :)
Hello! I've added that PHP code to the functions of my child theme, but it's still the same.
What I want is that when someone searches for a word, in the results ONLY WooCommerce products appear (without description, with price, reviews)
As you would on a normal store page.
The code should work.
Is it at least only searching for products now?
If not then have you tried the clearing your caching plugins?
Hello! I use WP Rocket + Cloudflare.
I added the code, I deleted cache in both places, but it does not do anything, it's as if the code was not there.
All types of files are shown in the results.
I have forwarded this to Tom and see if he can see a reason why the code wouldn't work.
Thanks for your patience :)
I'm not seeing the code in your website source.
Just to confirm:
1. You've placed it in your child theme functions.php file
2. Your child theme is active
If so, things must still be cached. Perhaps you have some sort of server caching in effect?
Hello Tom!
Yes, I put it in my child theme's functions.php. (active)
You do not see the code because I deleted it after checking that it did not do anything.
Can you re-add it so I can see why it isn't working?
Hello Tom! I have already added the code to the functions.php
Aha, there was an error in the snippet. Can you try the updated one?: https://docs.generatepress.com/article/generate_navigation_search_output/
Hello Tom! I checked the link you sent me and the code is the same:
add_filter( 'generate_navigation_search_output', 'tu_wc_navigation_search' );
function tu_wc_navigation_search() {
printf(
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
<input type="hidden" name="post_type" value="products" />
</form>',
esc_url( home_url( '/' ) ),
esc_attr( get_search_query() ),
esc_attr_x( 'Search', 'label', 'generatepress' )
);
}
Hi there,
can you clear your browser cache and revisit the link Tom provided here
as the code is different to what you are displaying.