Filter, search, and sort a product table

WooCommerce / Product Table

Two different settings narrow a table. Dropdown filters only hide rows that are already loaded. Category, price, stock, and similar attributes change the product query before the table is built.

Add filters to put dropdowns above the table. Each filter searches the matching column, so that column has to be in columns.

FilterDropdownNeeds this column
categoriesProduct categories. category is the same filter.categories
tagsProduct tags.tags
stockIn stock or out of stock, matched against the stock cell.stock
att:colorTerms for that attribute. Add a label with a third part: att:color:Color.att:color
tax:product_brandTerms for that taxonomy. Optional label: tax:product_brand:Brand.tax:product_brand
[yh_wc_product_table columns="image,name,att:color,att:size,stock,price,buy" filters="categories,att:color:Color,att:size:Size,stock" reset_button="true"]

reset_button="true" adds a Reset button above the table. It clears the dropdowns, the search box, and the sort, and puts the table back to the original order.

These dropdowns filter the current page of results in the browser. They do not load a new set of products from WooCommerce. A category dropdown cannot reveal a product that category or product_limit already left out.

AttributeDefaultValues
search_boxBottomtop, bottom, both, or false. true means bottom.
search_termEmptyText already typed into search when the table loads. search does the same thing.
instant_searchfalsetrue filters as the customer types, without waiting for Enter.
paginationBottomSame positions as the search box.
page_lengthBottomThe “show X entries” control. Same positions, or false.
totalsBottom“Showing 1 to 25 of 80”. Same positions, or false.
paging_typenumbersnumbers, simple, simple_numbers, full, or full_numbers.
rows_per_page25Capped at 200. -1 shows every row from the query on one page.
load_morefalsetrue replaces numbered pages with a Load more button.
lazy_loadfalseLoad rows over AJAX instead of printing them all in the page.
product_limit500Maximum products in the query. Hard cap 1000.

With the default settings, search runs in the browser on rows already printed. Turn on lazy_load="true" when the catalog is large enough that the first page should stay small. Products past product_limit are not in the table, so search cannot find them.

Choose which products are queried

These attributes run before the table renders. Combine them. A product has to match all of them.

AttributeExampleNotes
categorycategory="hoodies,shirts"Category slugs, comma-separated. Not the category name.
exclude_categoryexclude_category="sale"Slugs to leave out.
tagtag="organic"Tag slugs.
includeinclude="12,48,90"Only these product IDs.
excludeexclude="15,16"Skip these product IDs.
product_typeproduct_type="simple"simple, variable, grouped, or external.
min_price / max_pricemin_price="10" max_price="100"Leave either one at 0 for no bound on that side.
in_stock_onlytrueSkip out-of-stock products.
on_sale_onlytrueOnly products on sale.
featured_onlytrueOnly featured products.
taxonomy and termtaxonomy="pa_color" term="blue"One taxonomy term. Attribute archives use this for you.

Shoppers only see published products. A logged-in user who can edit products can pass status, for example status="publish,private".

Default sort

sort_by is the column used on first load. The default is menu_order, which is the WooCommerce product order. sort_order is asc or desc.

[yh_wc_product_table columns="sku,name,price,buy" sort_by="price" sort_order="asc" in_stock_only="true"]

Customers can still click another heading to sort, except image, buy, and the details button.

Common mistakes

The dropdown does nothing

The filter searches a column by its class. If that column is not in the table, there is nothing to search.

Fix: Add the matching column. A stock filter needs stock in columns. An att:color filter needs att:color in columns.

Search cannot find a product you know is published

The product was never queried. product_limit stops at 500 by default, and category, stock, or price attributes may already have excluded it.

Fix: Raise product_limit (maximum 1000) or remove the query attribute that leaves it out. For a large catalog, use lazy_load="true".

Category filter and category attribute mixed up

category="hoodies" limits the query. filters="categories" only adds a dropdown over rows already loaded.

Fix: Use category when the table should start as one category. Use filters when the customer should switch category inside a table that already contains those products.