Skip to main content
Querying products utilizes the “WordPress Loop”. This makes things nice and familiar if you are already familiar with WordPress queries. In order to get products, you will want to to specify the sc_product post type in the query.

Simple Query Example

Here is a query example. To query the posts, you will need to specify sc_product as the post type.
php

Querying Product Posts

This will return a posts query. You can show the the title (the product name) and the excerpt (the product description) for example.
php

Getting Product Data From The Post

However, you will likely want to display the product data, such as the price amount, whether it is out of stock, and more. You can do that in several ways.

In the loop

Since we are already in the loop, and have called $products->the_post(), you can use sc_get_product() to fetch the current posts’ product:
php

Outside the loop

However, if you are not in the loop, you can still use the sc_get_product function, and pass a post or post id:

Full Example

php

Querying Variant Options

You can also query by a variant option or multiple variant options by using the variant_options parameter.

Querying a single variant option

Querying products by option:

Querying multiple variant options

When querying multiple variant options, you will want to pass a relation argument, to let the query know if these options are inclusive or exclusive. Here’s an example to get products that are small and orange.
Whereas here is an example to get products that are small, medium OR orange: