Skip to content

Instantly share code, notes, and snippets.

@rajeebbanstola
Created January 5, 2016 11:27
Show Gist options
  • Save rajeebbanstola/c337a70dd952d61dd8b4 to your computer and use it in GitHub Desktop.
Save rajeebbanstola/c337a70dd952d61dd8b4 to your computer and use it in GitHub Desktop.
Fetch products from specific category in WooCommerce
<?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