Last active
September 6, 2023 09:41
-
-
Save andykillen/38e951ee2866611f65b47d5efd7d0d40 to your computer and use it in GitHub Desktop.
taxonomy queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = [ | |
'post_type' => 'product', | |
'posts_per_page' => 24, | |
'post_status' => 'publish', | |
'tax_query' => [ | |
'relation' => 'AND', | |
[ | |
'taxonomy' => 'pa_brand', | |
'field' => 'slug', | |
'terms' => 'nike', | |
], | |
[ | |
'taxonomy' => 'pa_target_group', | |
'field' => 'slug', | |
'terms' => ['men'], | |
], | |
[ | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => ['sneakers'], | |
] | |
] | |
]; | |
$result = get_posts($args); |
note that taxonomies created with WooCommerce UI are prefixed with "pa_"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gets the first 24 posts that are "brand = nike" , "target_group = men", and "product_cat = sneakers"