WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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.