Created
September 27, 2018 08:07
-
-
Save navnit-viradiya/c19f3e1cdb67a60596df3f790f8bff12 to your computer and use it in GitHub Desktop.
Wp_query with a custom taxonomy.
This file contains 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 = array( | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'posts_per_page' => -1, | |
'tax_query' => array( | |
'relation' => 'AND', | |
array ( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => 'category1' ), | |
array ( | |
'taxonomy' => 'product_tag', | |
'field' => 'slug', | |
'terms' => array('category2'), | |
) | |
), | |
); | |
$the_query = new WP_Query( $args ); | |
$count = $the_query->post_count; | |
if ( $the_query->have_posts() ) : | |
while ( $the_query->have_posts() ) : $the_query->the_post(); | |
$the_query->the_post(); | |
echo '<li>' . get_the_title() . '</li>'; | |
endwhile; | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment