Query WooCommerce Products based on Attribute
-
I’m trying to query WooCommerce products based on a specific attribute. For example, I set up an attribute called
colour
, with possible values ofred
orgreen
.I want to select all products with a colour value of “green”, so I query using the following:
$args = array( 'post_type' => 'product', 'meta_query' => array( array( 'key' => 'pa_colour', 'value' => 'green', 'compare' => '=' ) ) ); query_posts($args);
I understand it that WooCommerce attributes are preceded with
pa_
, but any variant of the attribute name is just as unsuccessful. Where am I going wrong? Is it possible to query attributes in this way?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Query WooCommerce Products based on Attribute’ is closed to new replies.