Skip to content

Instantly share code, notes, and snippets.

@sajibsrs
Created July 25, 2017 21:51
Show Gist options
  • Save sajibsrs/e408585e353f949636c6270eb4ba8d2a to your computer and use it in GitHub Desktop.
Save sajibsrs/e408585e353f949636c6270eb4ba8d2a to your computer and use it in GitHub Desktop.
Woocommerce 3 + custom featured product by category loop, exclude subcategories
$term = get_queried_object();
$tax_query = array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $term->term_id,
'include_children' => false // If you want to disable subcategories
),
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN',
)
);
$query_args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => 2,
'tax_query' => $tax_query,
);
$featured_query = new WP_Query( $query_args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment