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]
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.