-
-
Save raiden808/b435f89923d587b3f0208de14cb5dedd to your computer and use it in GitHub Desktop.
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
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