# 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**

```tsx
import { useWpProducts, useWpCurrency } from "@forgewp/woocommerce"

export default function ProductCatalog() {
  const { products, loading, error } = useWpProducts({ perPage: 8 })
  const { formatPrice } = useWpCurrency()
  if (loading) return <p>Loading products...</p>
  if (error) return <p role="alert">{error}</p>
  return <ul>{products.map(product => (
    <li key={product.id}>{product.name || product.title} — {formatPrice(product.price)}</li>
  ))}</ul>
}
```

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.

---

Source: [Catalog Queries and Product Context](https://www.forgewp.dev/docs/woocommerce/woo-catalog/products)
