- This topic has 20 replies, 4 voices, and was last updated 4 years, 1 month ago by David.
-
AuthorPosts
-
February 10, 2019 at 9:59 am #806762Pedro
Hello! I would like for the search results to show only products, not pages or blog articles.
How can I do it? Thank you!
February 10, 2019 at 5:24 pm #806949LeoStaffCustomer SupportHi there,
See the first example here:
https://docs.generatepress.com/article/generate_navigation_search_output/Let me know π
February 10, 2019 at 6:04 pm #806957PedroHello! And where can I place that code? I’m a novice
February 10, 2019 at 7:30 pm #806983LeoStaffCustomer SupportAdding PHP: https://docs.generatepress.com/article/adding-php/
We also specified this at the bottom of the articles π
February 11, 2019 at 11:02 am #807600PedroHello! 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.
February 11, 2019 at 4:27 pm #807821LeoStaffCustomer SupportThe code should work.
Is it at least only searching for products now?
If not then have you tried the clearing your caching plugins?
February 11, 2019 at 5:56 pm #807882PedroHello! 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.
February 11, 2019 at 10:03 pm #807953LeoStaffCustomer SupportI have forwarded this to Tom and see if he can see a reason why the code wouldn’t work.
Thanks for your patience π
February 12, 2019 at 9:24 am #808512TomLead DeveloperLead DeveloperI’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 activeIf so, things must still be cached. Perhaps you have some sort of server caching in effect?
February 13, 2019 at 2:29 pm #809749PedroHello 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.
February 13, 2019 at 5:58 pm #809835TomLead DeveloperLead DeveloperCan you re-add it so I can see why it isn’t working?
February 19, 2019 at 3:35 pm #814976PedroHello Tom! I have already added the code to the functions.php
February 19, 2019 at 5:56 pm #815036TomLead DeveloperLead DeveloperAha, there was an error in the snippet. Can you try the updated one?: https://docs.generatepress.com/article/generate_navigation_search_output/
February 19, 2019 at 6:52 pm #815069PedroHello 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' ) ); }
February 20, 2019 at 5:14 am #815399DavidStaffCustomer SupportHi there,
can you clear your browser cache and revisit the link Tom provided here
as the code is different to what you are displaying.
-
AuthorPosts
- You must be logged in to reply to this topic.