Archived topic
Posts dates in blog roll not in chronological order
5 replies · Started by Vranjes on February 18, 2023
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.
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' );
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
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.
Many thanks.
You're welcome