related products
// WP_Query arguments
$args = array(
'post_type' => array( 'product' ),
'post_status' => array( 'publish' ),
'order' => 'ASC',
'orderby' => 'id',
'tax_query' => array(
array(
'taxonomy' => 'category',
'terms' => '1',
'field' => 'term_id',
'operator' => 'NOT IN',
),
),
);
// The Query
$related_products = new WP_Query( $args );
// The Loop
if ( $related_products->have_posts() ) {
while ( $related_products->have_posts() ) {
$related_products->the_post();
// do something
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();