WordPress search form by category not working?
-
Objective
I am trying to create different search forms for two different landing pages. Thus, users who end up on landing
page A
will only be able to search for products with categoriesMan
andBook
. Users landing onpage B
will only be able to search for products with categoriesBeast
andFunny
.Here is my example setup in WooCommerce: https://i.stack.imgur.com/3uGjl.png
What I have tried
Based on this link, I have tried the following search function for
page A
.<form role="search" method="get" id="searchform" action="https://test.com/"> <div> <label for="s">Search for (Man and Book):</label> <input type="text" value="" name="s" id="s" /> <input type="hidden" value="1" name="sentence" /> <input type="hidden" value="product" name="post_type" /> <input type="hidden" value="product_cat" name="man,book" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form>
Problem
If I key in
GetAllX
into the search form, I expect to seeGetAllX (Copy 2)
only. Instead, I seeGetAllX (Copy 2)
andGetAllX
.Also, when I key in
test
, I expect to seeTest product 2
only. Instead, I see bothTest product 2
andTest Product
.Questions
1) Why is WordPress behaving like this? Can someone help me out with this, please?
2) If there is an easier way to create search forms for different product categories based on landing pages, please do let me know.
- The topic ‘WordPress search form by category not working?’ is closed to new replies.