I am using the following two codes to generate a wordpress search and a woo commerce product search? Is there a code to merge theme into one search bar doing both functions?
<?php get_search_form(); ?>
<?php get_product_search_form(); ?>
I am using the following two codes to generate a wordpress search and a woo commerce product search? Is there a code to merge theme into one search bar doing both functions?
<?php get_search_form(); ?>
<?php get_product_search_form(); ?>
You must be logged in to post a comment.
get_search_from(); covers both.
get_product_search_form() is same as get_search_from() just that it restricts the wordpress search to products only.
If you see the markup of both the functions, there’s only one difference. There is an additional post type value set as a product.
So,
I used the plugin Relevanssi which allows you to include custom post types (including woocommerce products) in the search results along with posts.
For those using JQuery, you can easily append the hidden post type input to any search form when the page is loaded. Just add the hidden input that specifies which type of search to run like the following example that I had to do for the DIVI search bar to search products instead of blog:
You can adapt this to your own site by changing around the selector in the jQuery line that defines the
diviSearchForm$
reference to whatever form(s) you want to target.Also, if you want to search all post types and not just product, change the value
product
value toany