Advertisement
helgatheviki

SQL Query product variations by parent category

May 3rd, 2023
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. global $wpdb;
  2.  
  3. $sql = "
  4. SELECT p.ID, p.post_parent
  5. FROM {$wpdb->posts} as p
  6. INNER JOIN {$wpdb->term_relationships} AS tr ON ( p.post_parent = tr.object_id)
  7. WHERE tr.term_taxonomy_id IN ( 51, 52 )
  8. AND p.post_type = 'product_variation' AND p.post_status = 'publish' ORDER BY p.ID ASC
  9. ";
  10.  
  11. $variations = $wpdb->get_results( $sql );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement