Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

'Orderby' date help WordPress

  • SOLVED

Hi folks,

I have the code below on my website. Basically, as you'll see, it displays two posts from the blog with the title, date, excerpt and link to the full post.
The problem is that I would like it to only display the two most recent posts - the newest first.
Currently it displays the two oldest posts, which isn't what I'm looking for.

Any help would be greatly appreciated!

<?php







$args = array( 'numberposts' => 2, 'order'=> 'ASC', 'orderby' => 'date' );







$postslist = get_posts( $args );







foreach ($postslist as $post) : setup_postdata($post); ?>







<div>


















<?php the_title(); ?> <br/>



<?php the_date(); ?>







<?php the_excerpt(); ?>
<a href="<?php echo get_permalink(); ?>">Read More</a>
<br/><br/>




</div>







<?php endforeach; ?>

</div>

<?php endforeach; ?>


Answers (5)

2011-05-04

Kailey Lampert answers:

Have you tried changing 'order'=> 'ASC' to 'order'=> 'DESC'


FPHT comments:

That worked perfectly, thanks! You and Maor both posted the same response at the same time so I'll split the money between you.

Many thanks :-)

2011-05-04

Maor Barazany answers:

Please try to change

'order'=> 'ASC'

to

'order'=> 'DESC'


FPHT comments:

That worked perfectly, thanks! You and Kailey both posted the same response at the same time so I'll split the money between you.

Many thanks :-)

2011-05-04

Daniele Raimondi answers:

Try changing order parameter to DESC

2011-05-04

Ryan Riatno answers:

try to descending order
'order' => 'DESC'


Ryan Riatno comments:

nnnnaahhh Wpquestion try to ordering the "Answer" order too to :D

2011-05-04

Chris Lee answers:

You need to change your query to use posts_per_page and rearrange the order


<?php

<strong>$args = array( 'posts_per_page' => 2, 'order'=> 'DESC', 'orderby' => 'date' );</strong>

$postslist = get_posts( $args );

foreach ($postslist as $post) : setup_postdata($post); ?>

<div>
<?php the_title(); ?> <br/>
<?php the_date(); ?>
<?php the_excerpt(); ?>
<a href="<?php echo get_permalink(); ?>">Read More</a>
<br/><br/>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>