Site logo

Archived topic

no chronological order in blog posts

7 replies · Started by Gerhard on April 15, 2021

Viewing posts 1–8 of 8

Hallo,
My entry-titles are german dates e.g. 02.12.2010, 02.12.2010/2, 02.12.2010/3...
How can I achieve that they are arranged in a chronological order on the archive pages? The oldest date should be shown last

Greetings Gerhard

Sorry - what I meant was that the oldest date should be shown FIRST

e.g. 01.10.2010, 02.10.201, 03.10.2010...

Greetings fro Cologne
Gerhard

Oh - Igot it. It must be ASCinstead of DESC.

Now it's ok. But it won't work on Dezember 2010???

(see link)

It won't work on Juli 2011 and September 2011 either!?

(The other months work)

Greetings from Cologne
Gerhard

Aah its the Title ( sorry i just read dates ).
The code above is just setting the order - by default that is the date value. Which should mean the dated order is correct - they just don't match your titles.

You can change the orderby to title - by using this instead:

add_action( 'pre_get_posts', function( $query ) {
  if ( $query->is_main_query() && ! is_admin() ) {
      $query->set( 'orderby', 'title' ); 
      $query->set( 'order', 'ASC' ); 
  }
} );

But i am not sure whether that will work correctly when the titles contain numbers.

Thanks a lot David!!!!! . Now everything works fine.

Greetings from Cologne
Gerhard

Thats great! Glad to be of help

This archived topic is closed to new replies.