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.

Revisions

  1. rajeebbanstola created this gist Jan 5, 2016.
    20 changes: 20 additions & 0 deletions product-from-category.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?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();