0

Hello I have a page template I use for my home page, The website is a Wordpress website with a Woocommerce store.

I show featured products using this snippet of code and it works well within my layout and grid.

<div class="woocommerce columns-4 ">
 <ul class="products">
      <?php
          $args = array(
              'post_type' => 'product',
              'posts_per_page' => 25,
              'tax_query' => array(
                    array(
                        'taxonomy' => 'product_visibility',
                        'field'    => 'name',
                        'terms'    => 'featured',
                    ),
                ),
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                wc_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
    ?>
 </ul><!--/.products-->
</div>

I wana duplicate this section and instead of the 'terms' => 'featured' I would like it to be 'terms' => 'recent_products'

However, are these terms like hooks? What would be the proper changes to pull in recent products instead of the featured ones?

Thanks!

1

Try this:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 25,
    'orderby' => 'date',
    'order' => 'DESC',
);

$loop = new WP_Query( $args );
3
  • This worked great, thanks so much! (it says i have to wait 5 more min to award an answer) – Patrick Dec 1 '17 at 2:41
  • What are those arguments called? Is there a list of them somewhere? All the available arguments? Thanks! – Patrick Dec 1 '17 at 2:42
  • 1
    Look at the documentation for WP_Query. – Jacob Peattie Dec 1 '17 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.