Site logo

[Resolved] Posts dates in blog roll not in chronological order

Home Forums Support [Resolved] Posts dates in blog roll not in chronological order

Home Forums Support Posts dates in blog roll not in chronological order

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2537885
    Vranjes

    Hi
    I noticed today that suddenly posts in the blog roll are not in chronological order. I see the same in several sites with GP theme. Can somebody tell me why this happened?

    Checked in the support forum and have seen that some PHP code should be added somewhere but not sure where and how.

    #2537928
    David
    Staff
    Customer Support

    Hi there,

    GP doesn’t have anything to do with the post ordering, we leave the Main Query as WordPress sets it, which is to list Posts in reverse chronological order based on the published date.

    If that is not the case then there is a custom function or plugin that is changing the main query.

    If you want the posts listed in some other order, eg. by orderby modified date, then you can do that using a PHP snippet:

    function orderby_modified_posts( $query ) {
        if($query->is_main_query()) {
                $query->set( 'orderby', 'modified' );
           }
    }
    add_action( 'pre_get_posts', 'orderby_modified_posts' );
    #2538126
    Vranjes

    Hi
    Thank you for the reply. I contacted you because my hosting support told me this is theme issue, can show a screenshot. Now I am going to show them your reply.

    Could you tell me how to use this code and where to use it. Can it be done in Elements?
    Regards
    Jovo

    #2538155
    David
    Staff
    Customer Support

    This code:

    function orderby_modified_posts( $query ) {
        if($query->is_main_query()) {
                $query->set( 'orderby', 'modified' );
           }
    }
    add_action( 'pre_get_posts', 'orderby_modified_posts' );

    Is PHP, this doc explains how to add PHP:
    https://docs.generatepress.com/article/adding-php/

    TLDR: Are you you using a Child Theme?
    If Yes, then the snippet can be added to your Child Themes > functions.php
    If No, then use the Code Snippets plugin ( link in the above Doc ), to create a new snippet for that code.

    #2538316
    Vranjes

    Many thanks.

    #2538569
    David
    Staff
    Customer Support

    You’re welcome

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