Raymond Seger
Raymond Seger

Reputation: 1130

How do i make a WP_Query to get product variations with specific attribute key and attribute value?

How do i make a WP_Query to get WC_Product_Variation with specific attribute key and attribute value?

All i know is how to get WC_Product

$all_products_query = new WP_Query( array(
'post_type'         => 'product',
'post_status'       => 'publish',
'posts_per_page'    => '-1',
) );

Upvotes: 0

Views: 1149

Answers (1)

softbrewery
softbrewery

Reputation: 501

You can use meta_query --refer https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

     $args = array(
         'post_type' => 'product',
         'meta_key' => 'key',
         'meta_value' => 'value'
      );
     $query = new WP_Query( $args );

Upvotes: 1

Related Questions