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 Answer 1

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
    Commented Dec 1, 2017 at 2:41
  • What are those arguments called? Is there a list of them somewhere? All the available arguments? Thanks!
    – Patrick
    Commented Dec 1, 2017 at 2:42
  • 1
    Look at the documentation for WP_Query. Commented Dec 1, 2017 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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