Skip to content

Instantly share code, notes, and snippets.

@raiden808
Last active June 3, 2018 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raiden808/b435f89923d587b3f0208de14cb5dedd to your computer and use it in GitHub Desktop.
Save raiden808/b435f89923d587b3f0208de14cb5dedd to your computer and use it in GitHub Desktop.
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