Query WooCommerce Products based on Attribute
attributes, woocommerce, wordpress
Solution
I know this is an old one, but just in case someone stumbles upon it like I did today -- Woocommerce (I'm using v2.6.2) appears to store these custom attributes as taxonomies.
I suspect the correct args for the original question would look like this:
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'pa_on',
'field' => 'name',
'terms' => 'yes'
)
)
);
Using the appropriate values for my installation, it solved my problem.
Problem
This one's driving me nuts.. I'm trying to query and output WooCommerce products based on a specific attribute. For example, I set up an Attribute called `on`, with possible values of `yes` or `no`. I query using the following: ``` $args = array( 'post_type' => 'product', 'meta_key' => 'pa_on', 'meta_value' => 'yes', 'posts_per_page' => -1 ); query_posts($args); ``` The `meta_key` is crucial perhaps; if I call it `on` I get nothing. If I call it `pa_on` (because that's how I understand WooCommerce custom attributes to be constructed) I get nothing. However, if I try a different query and use `_featured`, which is a standard WooCommerce custom meta thingy, it returns the relevant featured posts. Help, anyone?