Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

According to:http://codex.wordpress.org/Function_Reference/query_posts

To show all posts in a category:

query_posts( array ( 'category_name' => 'The Category Name', 'posts_per_page' => -1 ) );

Works great, but if I want to show the posts

ORDER BY ID DESC

Anyone have any idea how to do that?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You need to use this to parameters orderby and order

<?php query_posts( array( 'category_name' => 'my_category_slug', 'orderby' => 'ID', 'order' => 'DESC', 'posts_per_page' => -1 ) ); ?>
share|improve this answer
    
Thanks again, it works! –  Muazam Aug 27 '11 at 20:25
add comment

the param order can list via DESC and the param orderby sort by ID for your example:

query_posts( 
   array ( 'category_name' => 'The Category Name', 
           'posts_per_page' => -1,
           'orderby' => 'ID',
           'order' => 'DESC'
   )
);

oder is only usable with ASC or DESC and orderby can use all fiels of the table posts.

share|improve this answer
    
Thank you! It works. –  Muazam Aug 27 '11 at 20:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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