Created
January 5, 2016 11:27
-
-
Save rajeebbanstola/c337a70dd952d61dd8b4 to your computer and use it in GitHub Desktop.
Fetch products from specific category in WooCommerce
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
<?php | |
$args = array( | |
'post_type' => 'product', | |
'orderby' => 'title', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'id', | |
'terms' => $category | |
), | |
), | |
'posts_per_page' => $product_number | |
); | |
$featured_query = new WP_Query( $args ); | |
while ($featured_query->have_posts()) : | |
$featured_query->the_post(); | |
$product = get_product( $featured_query->post->ID ); // By doing this, we will be able to fetch all information related to single WooCommerce Product | |
endwhile; | |
wp_reset_query(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment