To display the post order by modified date in wordpress

I have to display the posts oder by last modified date. So I used the code bellow.

$args = array(
    'post_type' => $post_type,
    'numberposts' => '2',
    'orderby' => 'modified',
    'order'=> 'ASC',
);
$the_query = new WP_Query( $args );

But I could not find any update in the above code. Should i use something else instead of 'orderby' => 'modified' in the argument.

Related posts

Leave a Reply

2 comments

  1. You should use DESC for order.

    Try this:

     $the_query = new WP_Query( array(
         'post_type'   => $post_type,
         'numberposts' => '2',
         'orderby'     => 'modified',
         'order'       => 'DESC',
     ));
    

    Using DESC will give you the latest post first(descending order).

    EDIT:

    As Andrew commented, the default value for order is DESC and can thus be omitted from the code:

     $the_query = new WP_Query( array(
         'post_type'   => $post_type,
         'numberposts' => '2',
         'orderby'     => 'modified',
     ));