Wordpress/Woo how to search in category?

2019-08-10 14:13发布

问题:

In Wordpress / WooCommerce I want to search by Category but somehow I cant get it to work. The normal Search works and gives me this url http://localhost:8888/rwdr/search/[searchkeyword] how does the url look like when searching in a category?

<form role="search" method="get" id="searchform2" action="" class="">
    <ul class="radio-ul">
      <li>
        <label for="typBA" class="typ typBA "></label>
        <input name="category" id="typBA" value="BA" type="radio">
      </li>
      <li>
        <label for="typBAX7" class="typ typBAX7 "></label>
        <input name="category" id="typBAX7" value="BAX7" type="radio">
      </li>
      <li>
        <label for="typBASL" class="typ typBASL "></label>
        <input name="category" id="typBASL" value="BASL" type="radio">
      </li>
    </ul>

    <label for="InputBox">Input Box</label>
    <input type="text" value="" id="first" name="s" />
    <input type="hidden" value="" name="x" /> </form>

I really appreciate any help!

回答1:

You can do a search using standard query in your url

yoursite.com/?post_type=product&taxonomy=product_cat&term=your_category_slug&s=a

To get the URL, you can build a form like this,

<form method="get" action="" role="search">
    <input type="hidden" name="post_type" value="product">
    <input type="hidden" name="taxonomy" value="product_cat">
    <input type="hidden" name="term" value="your_category_slug">
    <input type="search" name="s" value="">
    <input type="submit" value="Search">
</form>


回答2:

In WordPress, I use a plugin called "Search Everything", where you can set if you want to add categories, tags and many other options to the search results. It's pretty easy to use and it works fine to me.