1

I have been searching for an answer and it seems like there are a lot of answers for the opposite issue. I am trying to sort by publish date, not by date modified, using this code:

query_posts($query_string . '&orderby=date&order=DESC&posts_per_page=-1');

But it is still sorting on date modified not publish date, can anyone help?

Thanks in advance!

  • 2
    I don't see a path in code that might lead to that. Are you sure that results are wrong? Are you sure that this query applies to results you are seeing at all? What does $query_string hold? – Rarst Dec 8 '13 at 22:35
  • 1
    Sidenote: you likely don't want to use query_posts(). You probably meant to use get_posts() or a pre_get_posts filter. See the docs: codex.wordpress.org/Function_Reference/query_posts – Robbert Dec 8 '13 at 22:47
2

You should not have to specify orderby=date. That is the default. If you look at the query, you will see that the field used is post_date, which is the publication date and not the modification date-- post_modified.

You can prove this just by dumping $wp_query after your call to query_posts. Or try:

$q = new WP_Query('posts_per_page=-1');
var_dump($q->request);

With no other parameters you get ORDER BY wp_posts.post_date DESC.

If you are not getting that order there is already a filter that is altering default behavior. What is adding that filter I can't guess.

And yes, please don't use query_posts.

It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. While easy to use, the function is also prone to confusion and problems later on. See the note further below on caveats for details.

http://codex.wordpress.org/Function_Reference/query_posts (emphasis mine)

  • OK thanks, I think it must be another query or plugin interfering then, and thank you for the sidenote, I meant to get rid of all my query_posts. Thanks! – Donna Dec 9 '13 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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