I want to modify my WordPress site theme feature, and modify the search tool from header to show just related products, instead showing me blog post. I searched a little, and found that just need to modify the query, so can use for searching woo products. This is my current search query:
<form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <?php printf( '<input type="search" class="et-search-field" placeholder="%1$s" placeholder="%2$s" name="s" title="%3$s" />', esc_attr__( 'Search …', 'Divi' ), get_search_query(), esc_attr__( 'Search for:', 'Divi' ) ); ?> <button type="submit" id="searchsubmit_header"></button> </form>
i found that i should put this line:
<input type="hidden" class="" value="product" name="post_type" />
bellow
<form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
So it should looks like this:
<form role="search" method="get" class="et-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>"> <input type="hidden" class="" value="product" name="post_type" />
but still show me mixed results from Woo Products and Pages/Blog posts.
So my question is what to modify in query to search just for WooCommerce products instead of blog posts. Thanks in advance.
Advertisement
Answer
Welcome to Stack Overflow.
Add a hidden field to search for products.
<input type="hidden" value="product" name="post_type">
Live example from one of my sites.
Example has separate forms to search posts, products, news.
Best wishes, Mitchell