[Support request] Search results products

Home Forums Support [Support request] Search results products

Home Forums Support Search results products

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #806762
    Pedro

    Hello! I would like for the search results to show only products, not pages or blog articles.

    How can I do it? Thank you!

    #806949
    Leo
    Staff
    Customer Support

    Hi there,

    See the first example here:
    https://docs.generatepress.com/article/generate_navigation_search_output/

    Let me know πŸ™‚

    #806957
    Pedro

    Hello! And where can I place that code? I’m a novice

    #806983
    Leo
    Staff
    Customer Support

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    We also specified this at the bottom of the articles πŸ™‚

    #807600
    Pedro

    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.

    #807821
    Leo
    Staff
    Customer Support

    The code should work.

    Is it at least only searching for products now?

    If not then have you tried the clearing your caching plugins?

    #807882
    Pedro

    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.

    #807953
    Leo
    Staff
    Customer Support

    I have forwarded this to Tom and see if he can see a reason why the code wouldn’t work.

    Thanks for your patience πŸ™‚

    #808512
    Tom
    Lead Developer
    Lead Developer

    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?

    #809749
    Pedro

    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.

    #809835
    Tom
    Lead Developer
    Lead Developer

    Can you re-add it so I can see why it isn’t working?

    #814976
    Pedro

    Hello Tom! I have already added the code to the functions.php

    #815036
    Tom
    Lead Developer
    Lead Developer

    Aha, there was an error in the snippet. Can you try the updated one?: https://docs.generatepress.com/article/generate_navigation_search_output/

    #815069
    Pedro

    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' )
    	);
    }
    
    #815399
    David
    Staff
    Customer Support

    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.

Viewing 15 posts - 1 through 15 (of 21 total)
  • You must be logged in to reply to this topic.