How to Display WooCommerce Products with Shortcodes and Blocks
The [products] shortcode covers almost every listing. Its defaults, its visibility values and its 30-day result cache explain most of the surprises; the Product Collection block is the block-editor equivalent.
Use [products] and set only what you need — limit, columns, category, orderby — because its defaults are not what most people assume: no limit means every product, and results are cached for up to 30 days.
[products limit="8" columns="4" orderby="date" order="DESC"]
A quick reality check from a WordPress 7.1.5 + WooCommerce 11.3.1 test store with four products — Wool Scarf set to Hidden, Canvas Tote out of stock with "Hide out of stock items from the catalog" on:
[products limit="10" columns="4"] → Cotton T-Shirt, Linen Shirt
[products ids="<scarf ID>,<tote ID>"] → nothing, just <div class="woocommerce columns-4 "></div>
Naming products by ID does not bypass catalog visibility or the out-of-stock setting.
Attributes and their real defaults
| Attribute | Default | What it does |
|---|---|---|
limit |
-1 (all products) |
Number of products. Old alias: per_page |
columns |
The Products per row setting (4 unless changed) | Adds columns-N to the wrapper and list |
rows |
empty | If set, limit becomes columns × rows |
orderby |
The store's default sorting (menu_order unless changed) |
menu_order, title, date, modified, price, popularity, rating, rand, id |
order |
empty | ASC or DESC. Accepted for title, date and price; ignored by popularity and rating |
ids / skus |
empty | Comma-separated product IDs or SKUs |
category |
empty | Comma-separated category slugs (or IDs) |
cat_operator |
IN |
IN, NOT IN, AND. Old alias: operator |
tag / tag_operator |
empty / IN |
Tag slugs only, same operators |
attribute / terms / terms_operator |
empty / empty / IN |
attribute="color" terms="red,blue". Old alias for terms: filter |
visibility |
visible |
See the next section |
on_sale, best_selling, top_rated |
not set | true switches the listing type |
paginate |
false |
Adds result count, sorting and pagination |
class |
empty | Extra class on the wrapper |
cache |
true |
false skips the result cache |
Three behaviours catch people:
on_sale,best_sellingandtop_ratedare exclusive. Only one applies, in that order of priority.best_sellingandtop_ratedforce their own descending sort, so anorderbynext to them is overridden.- The URL wins over
orderby. If the page URL has?orderby=price, every[products]on that page sorts by price. Withpaginate="true", pages are read from?product-page=2. categorywithcat_operator="AND"matches products in all listed categories and stops including child categories. WithIN, child categories are included.
What visibility and ids really filter
Catalog visibility is stored as hidden terms (exclude-from-catalog, exclude-from-search, featured). The visibility values query those terms, and they are narrower than their names:
| Value | Shows only products set to | Also drops out-of-stock (hide setting on) |
|---|---|---|
visible (default) |
Shop and search results, or Shop only | Yes |
catalog |
Shop only | No |
search |
Search results only | No |
hidden |
Hidden | No |
featured |
Featured, among the products visible would show |
Yes |
So visibility="catalog" is not "everything in the catalog"; on most stores it returns nothing.
ids and skus do not bypass visibility. They are added to the query alongside the default visible filter. A product set to Hidden, or out of stock while Hide out of stock items from the catalog is ticked, is dropped even when you name it. To list Hidden products on purpose, use visibility="hidden". An empty result prints only the wrapper, with no "no products" message:
<div class="woocommerce columns-4 "></div>
Recipes
[products limit="4" columns="4" visibility="featured"]
[products category="mens-shoes" limit="12" columns="3" paginate="true"]
[products category="sale" cat_operator="NOT IN" limit="8"]
[products on_sale="true" limit="8" orderby="price" order="ASC"]
[products best_selling="true" limit="6" columns="3"]
[products attribute="color" terms="red" limit="8"]
[products ids="42,57,91" orderby="post__in"]
orderby="post__in" is not in WooCommerce's list but falls through to WordPress, keeping the order of ids.
Single products and buttons:
[product_page id="42"]
[product id="42"]
[add_to_cart id="42" show_price="false" style=""]
[add_to_cart_url id="42"]
[add_to_cart] has a default inline style (border:4px solid #ccc; padding: 12px;); style="" removes it. It also takes sku, quantity and class.
Legacy shortcodes still registered
WooCommerce 11.3.1 still registers these. Each is [products] with different defaults:
| Shortcode | Defaults | Equivalent |
|---|---|---|
[recent_products] |
12, 4 columns, newest first | [products limit="12" orderby="date" order="DESC"] |
[featured_products] |
12, 4 columns, newest first | [products limit="12" visibility="featured" orderby="date" order="DESC"] |
[sale_products] |
12, 4 columns, by title | [products limit="12" on_sale="true" orderby="title"] |
[best_selling_products] |
12, 4 columns | [products limit="12" best_selling="true"] |
[top_rated_products] |
12, 4 columns | [products limit="12" top_rated="true"] |
[product_category] |
12, 4 columns, menu order; empty without category |
[products limit="12" category="…"] |
[product_attribute] |
12, 4 columns; empty without attribute |
[products limit="12" attribute="…" terms="…"] |
[product_categories] |
All categories, hides empty ones | No [products] equivalent: lists categories |
[related_products] |
4, random order | Related products for the current product |
The practical difference is limit: the legacy ones stop at 12, while a bare [products] lists the whole catalog.
How the result cache works
The shortcode caches the list of product IDs, not the HTML, in a wc_product_loop_… transient for 30 days. Prices, titles and images are rendered fresh on every load. The list is discarded when WooCommerce bumps its product query version: a product or variation is published or unpublished, a product's categories, tags or visibility terms change, its stock status or catalog visibility is set, or a product is saved. Edits that skip WooCommerce, such as direct SQL updates, leave the old list in place. Fix it with WooCommerce › Status › Tools › WooCommerce transients › Clear transients, or add cache="false" while testing.
orderby="rand" is cached too: up to six random orderings are stored and one is picked per load, so it rotates but is not truly random. A page cache sits on top of all this; see what WooCommerce can cache.
Shop-query customisations made with woocommerce_product_query do not reach shortcodes. Shortcodes have their own filter, woocommerce_shortcode_products_query.
The block alternative
In the block editor, the Product Collection block replaces the shortcodes. Its collections include Product Catalog, Featured Products, On Sale Products, Best Sellers, Top Rated Products, New Arrivals, Hand-Picked Products, Products by Category, Products by Tag and Related Products. Two differences matter:
- It runs its query on every load, without the shortcode's transient.
- Its Stock status filter is saved with the block, seeded from the hide setting when inserted. Changing the setting later does not update existing blocks.
Shortcodes still make sense in a Shortcode block, a widget, a page builder text element or content moved between sites. Layout and styling of the grid are in product card design.
Common mistakes
- A bare
[products]on a large store: it loads every product. Setlimitorpaginate. - Category names instead of slugs. "Men's Shoes" is probably
mens-shoes; a wrong slug gives an empty grid. - Expecting
idsto show hidden or out-of-stock products. - Judging an edit by a stale grid. Clear transients and the page cache before assuming the attributes are wrong.
If the shop itself is empty rather than one shortcode, start with WooCommerce products not showing.
Frequently asked
- Add columns="4", for example [products limit="8" columns="4"]. It sets the columns-4 class on the wrapper and the list; how those columns collapse on a phone is up to the theme's CSS. Without columns, the shortcode uses the Products per row setting, which defaults to 4.
- No. The shortcodes output the same product grid markup as the shop, and no attribute switches it to a list. Use columns="1" and add a class, then style that class as rows with your own CSS.
- Usually a category or tag given by name instead of slug, products that are Hidden or out of stock with the hide setting on (listing them by ids does not override this), or a visibility value that does not mean what it sounds like. An empty result prints an empty wrapper with no message.