Eren Labs JOURNAL TR
Product Catalog

WooCommerce Category Shortcode: Every Version, With Working Examples

Three shortcodes, three jobs. Copyable examples with the real default values, how child categories behave, how to exclude a category, and why a grid comes out empty.

In this article16 sections

The basic WooCommerce category shortcode is [product_category category="hoodies"], which shows products from one category. To combine categories, exclude one or add paging, use [products]. To show tiles for the categories themselves, use [product_categories]. Most mistakes come from mixing up the last two.

Below are examples you can paste, the default values taken from the WooCommerce 11.3.1 source, and a short list of reasons a grid comes out empty.

Which shortcode do you need?#

You wantUseKey attribute
———
Products from one categoryproduct_categorycategory
Products with filters, paging or several categoriesproductscategory, cat_operator
A grid of category tilesproduct_categoriesparent, ids, limit
Three shortcode jobs: one category, mix and filter, and category tiles
Pick the shortcode by what you want on the page.

Show products from one category#

Paste this into a Shortcode block:

[product_category category="hoodies"]

The value is normally the category slug. Find it under Products → Categories in the Slug column. If you leave the category out entirely, this shortcode prints nothing at all.

Its defaults, from class-wc-shortcodes.php, are 12 products, 4 columns, ordering by menu order and then title, ascending. Change them as attributes:

[product_category category="hoodies" limit="8" columns="4"]

WooCommerce products by category shortcode with more options#

The [products] shortcode does everything the first one does and more. Its default limit is different: it shows all matching products unless you set one. On a large category that makes a very long, slow page, so always add a limit or paging.

[products category="hoodies" limit="12" columns="4" paginate="true"]

Separate several categories with commas:

[products category="hoodies,caps" limit="12"]

By default a product in any of the listed categories appears. The cat_operator attribute changes that:

cat_operatorResult
——
IN (default)Products in at least one listed category
ANDOnly products that are in all listed categories
NOT INProducts in none of the listed categories

Child categories: included or not?#

With the default operator and with NOT IN, products in child categories count too. A shortcode for clothing also pulls products filed only under clothing’s subcategories. With AND, child categories are not included. You can see this in the products shortcode class.

This matters when a parent grid looks bigger than expected, or when an AND query returns nothing because your products sit in a child category instead of the parent. Our article on subcategories explains how to file them.

WooCommerce exclude category shortcode#

To list everything except one category:

[products category="clearance" cat_operator="NOT IN" limit="24" paginate="true"]

Because child categories are included in the exclusion, excluding a parent also removes its whole branch.

Order and filter the results#

The orderby attribute accepts values such as date, title, price, popularity, rating, menu_order, id and rand. A few useful combinations:

[products category="hoodies" orderby="popularity" limit="4"]

[products category="hoodies" orderby="date" order="DESC" limit="8"]

[products category="hoodies" on_sale="true" limit="8"]

You can also filter by a tag, or by an attribute together with its terms. Avoid random ordering on a cached page: visitors will see the same shuffle until the cache is rebuilt. The shop’s own sort rules are covered in default sorting, and the shortcode’s ordering does not change them.

WooCommerce category list shortcode: show category tiles#

[product_categories] prints a grid of categories with their images. Its defaults are no limit, ordering by name, 4 columns and hiding empty categories.

  • Top level only: [product_categories parent="0"]
  • Children of one category: use parent with that category’s numeric ID.
  • A hand-picked set: use ids with comma separated numeric IDs.
  • Include empty ones: [product_categories hide_empty="0"]

Find a category ID by hovering over its edit link under Products → Categories and reading tag_ID in the address. For tiles on the main shop page, you may not need a shortcode at all; see showing categories on the shop page.

Why the grid comes out empty#

  1. The slug is wrong. Copy it from the Categories screen instead of guessing from the name.
  2. The quotes are curly because the text came from a word processor. Retype them as straight quotes.
  3. The products are drafts, private or hidden from the catalogue.
  4. Every product is out of stock and your store hides out of stock items.
  5. You used AND and the products are only in child categories.
  6. The shortcode was pasted into a code block or a field that does not run shortcodes.
  7. A page cache is still showing an older version.

Test with [products limit="4"] on a draft page. If that shows products, shortcodes work and the problem is your filter.

Using shortcodes with block themes#

WooCommerce also offers product collection blocks that you configure visually. Blocks are often easier for editors, while shortcodes are compact and portable across page builders. Choose one approach for a given page and note it, so the next person knows where to edit.

Plan the page around what changes#

A shortcode only shows what is already in a category. If you build a page for products under 25.00 or for items on sale, somebody has to keep the category correct. After a price change, a manually filled category is soon wrong. Either use a shortcode filter such as on_sale, or have the category maintain itself. Our guide to adding products to categories by rules compares the options.

Categories that fill themselves with Smart Categories#

Smart Categories is a free plugin on WordPress.org. You describe a category with rules, such as price below 25 and on sale, preview the matching products, and the plugin adds and removes them as prices, stock and products change, plus a daily sweep. Products you added by hand are left alone.

Smart Categories showing a created category already filled with matching products
A smart category is filled by its rules, so any listing of it stays current.

The result is a normal WooCommerce category, so the core shortcodes work with it by slug. The plugin also has its own block and a shortcode in the form [scwc_products id="12" limit="12" columns="4"]. It can order the category page by best selling, newest, price or rating, and push out of stock products to the end or hide them. Generating a subcategory for every attribute value is a Pro feature.

A quick checklist before publishing#

Set a limit, check the grid on a phone, open it logged out, and click one product to confirm the link. If the page is a campaign, note the date to review it. For a featured block, which works differently from categories, see featured products. Keep a short list of pages that use shortcodes, so renaming a category slug does not silently empty one of them.

Worked example: a gifts under 25 page#

A shop wants one landing page listing affordable gifts. The first version is a draft page with a heading, two sentences of introduction and this block:

[products category="gifts" limit="24" columns="4" orderby="popularity" paginate="true"]

It works, but a gift priced at 32.00 is still filed under gifts and appears on the page. A shortcode has no way of knowing what the page title promises. The fix is to create a separate category for gifts under 25 and show that category instead. Someone then has to keep it correct after every price change, either by hand or by a rule.

Write the promise of the page next to its shortcode in your notes. When you review the page, check the five most expensive items against that promise.

Shortcodes and page speed#

Each product grid runs its own query and loads its own images. One grid is rarely a problem. A home page with six grids of 24 products asks the server and the visitor’s phone for far more. Show fewer items in each grid, link to the full category page for the rest, and keep paging for long lists. Check that your product images are sized sensibly, since images usually weigh more than the markup around them.

Where possible, link to the real category archive instead of rebuilding it on a page. The archive already has paging, sorting and its own address, and you avoid two pages competing to list the same products.

Testing after changes#

After renaming a category, moving products or updating your theme, open every page that uses a shortcode. Confirm that the slug still matches, that the count looks right and that the layout holds on a narrow screen. A shortcode with a stale slug fails quietly: there is no error message for you or the visitor, only an empty space where products used to be.

WooCommerce category shortcodes: frequently asked questions#


What is the shortcode to show products from a category?

Use the product_category shortcode with a category attribute set to the category slug. For paging, several categories or exclusions, use the products shortcode with the same category attribute and add limit, paginate or cat_operator as needed.


How do I show products from multiple categories?

Put the slugs in the category attribute separated by commas. By default a product in any one of them appears. Set cat_operator to AND to require all of them, remembering that child categories are not counted when AND is used.


How do I exclude a category from a product shortcode?

List that category in the category attribute and set cat_operator to NOT IN. Products in its child categories are excluded as well. Add a limit and paging, since an exclusion query can otherwise return most of your catalogue on a single page.


Why does my category shortcode show nothing?

Check the slug, use straight quotes, and confirm the products are published, visible in the catalogue and not hidden for being out of stock. A bare product_category shortcode without a category prints nothing. Test a plain products shortcode to confirm shortcodes run.


How do I display categories instead of products?

Use the product_categories shortcode. It shows category tiles, hides empty categories by default and can be limited to top level categories with parent set to zero, or to chosen categories with a comma separated list of numeric IDs.


More in Product Catalog

Keep exploring

All articles
Before you go Let Smart Categories do this in WooCommerce

Define the rules for a WooCommerce category once. Matching products enter automatically and leave when they no longer qualify.

Explore Smart Categories Get the free version

Free version on WordPress.org · Pro from $59/year