• Resolved hamil

    (@hamil1)


    The search box in the Storefront template header is for product searches only. I need the search results to include pages and posts as well. How to do it?
    Thank you in advance for your advice.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Roxy

    (@roxannestoltz)

    Hi @hamil1 ,

    Thanks for reaching out!

    I understand that you would like to extend the “Product search” widget to also search for posts and pages, is this correct?

    Please note that this search bar only searches for products. However, the default “Search” widget can be added to one of the widget areas created by Storefront to add that functionality.

    To do this you can follow the steps below:

    • Navigate to Appearance → Customize → Widgets
    • Choose where you would like to add the search widget:
    • Add the Search widget (not the Product search widget):

    Here’s a screenshot of how it appears when added to the “Below Header” widget area:

    On the other hand, if you would like to customize the default Storefront “Product search” box to include searches for posts and pages, this would require custom coding which is outside our scope of support.

    However, you can try the following code snippet to see if this works for you. I have tested the below custom code on my staging site which uses the latest version of WordPress and WooCommerce, and it is working as expected:?

    // Override WooCommerce default product search form
    add_filter( 'get_product_search_form', 'get_custom_product_search_form', 10, 1 );
    
    /**
     * Modify product search form HTML.
     *
     * @param string $form Default HTML markup of the search form.
     * @return string Modified HTML markup of the search form.
     */
    function get_custom_product_search_form( $form ) {
        $form = str_replace( '<input type="hidden" name="post_type" value="product" />', '', $form );
        return $form;
    }

    You need to add the code to your child theme’s?functions.php?file or via a plugin that allows custom functions to be added, such as the?Code snippets?plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update Storefront.

    Results before adding the code snippet:

    Results after adding the code snippet:

    Hope this helps!

    Thread Starter hamil

    (@hamil1)

    Hi @roxannestoltz

    Thank you for your excellent reply.

    I added the code to the function.php of the child theme and it works. Great!

    I don’t want to use the search widget because the two search fields can be confusing for visitors.

    Thank you for your help.

    • This reply was modified 1 year, 8 months ago by hamil.
    Roxy

    (@roxannestoltz)

    Hi @hamil1 ,

    I don’t want to use the search widget because the two search fields can be confusing for visitors.

    I hear you, that makes sense ??

    Glad to hear that the code has worked as expected on your end!

    Since this has been resolved, feel free to create a new topic should you need any further help.

    Also, if you have a few minutes, we’d love it if you could leave us a review:?

    https://www.ads-software.com/support/theme/storefront/reviews/

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Extending search to pages and posts’ is closed to new replies.