WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I have my posts ordered ascending (from oldest to newest) because I use Wordpress as a website to accompany a book published based on the original blog. To do this I put the following code just before The Loop in index.php of my custom version of the Connections theme:

    $wp_query->set('orderby', 'post_date');
    $wp_query->set('order', 'ASC');

This works fine for the main index and for when the posts are displayed by page, i.e.:

However, when the posts are retrieved by month or by category, the sort order defaults to DESC, i.e.: http://www.justanothersoldier.com/?cat=4


I just want everything to always be ASC. Are there monthly and category templates I need to edit? Thanks.

share|improve this question
up vote 0 down vote accepted

You can hook into the posts_clauses filter and change ASC to DESC there with a simply str_replace. The filter has one argument $pieces, which is an array of the MySQL statement parts.

share|improve this answer

In some cases it might be good to know that you can just add parameters to the url, like


which is sufficient if you use menu entries to access categories, each with their specific sort order defined by such an url parameter.

(How to associate certain categories with individual 'per-category-defined' sort order, so that it'll work even when selecting a category by clicking on the posts' category label - in which case the required url parameter gets lost again - is another question. I've posted that here: How to choose a sort order (for posts) per category? (ideally when creating a new category) - 1st answer again suggests to alter some code.)

share|improve this answer

Your Answer


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.