Get product variations in product loop
-
New to WC. I see that variations are stored in the wp_posts table as an additional post with the post parent set to, well, the “Product Post” that created them. Makes sense. My Question is how do I retrieve these efficiently? For instance:
<?php // Get $args = array( 'post_type' => 'product', 'posts_per_page' => 3, 'category' => 'care', 'order' => 'ASC' ); $plans = get_posts( $args ); foreach($plans as $plan): $args = array( 'post_parent' => $plan->ID, 'post_type' => 'product_variation', 'numberposts' => -1, 'post_status' => 'any' ); $variations = get_posts( $args ); // Do stuff with product variation data endforeach; ?>
The above works. However, there must be a better way?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Get product variations in product loop’ is closed to new replies.