Number of WooCommerce product categories while there is a search bar

I am creating a filter widget to display a WooCommerce product, followed by the number of products for a category, and it will also work when a search bar exists.

Like, there are three categories,

  • Notebooks (5),
  • Work tables (7),
  • Pills (12)

Now someone is looking for Asus and their 2 laptops, 4 desktop computers and 7 tables for Asus.

Now, in the category of the sidebar, it will show how many products match this category for the search.

I am currently displaying the default WP_Query counter using the tax_query parameter.

But it seems that it is very slow, because if there are 50 categories, the query is executed 20 times. I believe there is a better way to do this.

+4
source share

Source: https://habr.com/ru/post/1626649/


All Articles