ForgeWP

Catalog Queries and Product Context

Read the product-query contract, fallback behavior and the distinction between client queries and compiler product loops.

Catalog queries and product context

useWpProducts(params?) returns products, loading, error, total, totalPages, page and async refetch. Inputs are category, tag, search, minPrice, maxPrice, page, perPage and sortBy.

src/components/ProductCatalog.tsx
1import { useWpProducts, useWpCurrency } from "@forgewp/woocommerce"
2
3export default function ProductCatalog() {
4  const { products, loading, error } = useWpProducts({ perPage: 8 })
5  const { formatPrice } = useWpCurrency()
6  if (loading) return <p>Loading products...</p>
7  if (error) return <p role="alert">{error}</p>
8  return <ul>{products.map(product => (
9    <li key={product.id}>{product.name || product.title} — {formatPrice(product.price)}</li>
10  ))}</ul>
11}

Outside development the hook requests /forgewp/v1/products. If the response is unusable it falls back to browser mock/hydrated products; not all HTTP failures populate error. In local preview it returns the collection without equivalent query filtering or pagination. A visible catalog does not prove the endpoint succeeded.

useWpProduct(number) searches that loaded collection by ID; a string searches by SKU, not slug. It does not fetch an individual product endpoint, so a product outside the loaded page can be absent. Its returned error is currently always null.

useWpProductCategories() and useWpProductTags() read _taxonomy_product_cat and _taxonomy_product_tag from the mock/hydrated collection. They do not independently fetch live taxonomy endpoints.

Compiler loops

WpProductLoop accepts category, limit, orderBy, order, status and children. Local rendering supplies product post context; exported marker processing generates a wc_get_products() loop.

The no-argument useWpProductPrice, useWpProductSKU and useWpProductRating hooks emit compiler markers outside development. They are not asynchronous product-ID hooks. Inspect the exported PHP and context before using them; an arbitrary client island does not automatically replace their marker strings. The numeric-ID WpProductPrice component is a separate API.