Site logo

[Support request] no chronological order in blog posts

Home Forums Support [Support request] no chronological order in blog posts

Home Forums Support no chronological order in blog posts

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1735311
    Gerhard

    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

    #1735735
    David
    Staff
    Customer Support

    Hi there,

    try this PHP Snippet:

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

    Adding PHP: https://docs.generatepress.com/article/adding-php/

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

    #1736385
    Gerhard

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

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

    (see link)

    #1736393
    Gerhard

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

    (The other months work)

    Greetings from Cologne
    Gerhard

    #1736537
    David
    Staff
    Customer Support

    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.

    #1736817
    Gerhard

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

    Greetings from Cologne
    Gerhard

    #1736821
    David
    Staff
    Customer Support

    Thats great! Glad to be of help

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.