Instantly share code, notes, and snippets.

Embed
What would you like to do?
function filter_my_products(){
//slugs or id.
$selected_cats = array('shoes,clothes');
$args = array(
'post_type' => 'product',
'posts_per_page' => 7,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $selected_cats
),
)
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment