Created
July 25, 2017 21:51
-
-
Save sajibsrs/e408585e353f949636c6270eb4ba8d2a to your computer and use it in GitHub Desktop.
Woocommerce 3 + custom featured product by category loop, exclude subcategories
This file contains hidden or 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
$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