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.
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',
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With