Site logo

Archived topic

latest posts taxonomy based on update date

7 replies · Started by Nikos on June 11, 2021

Viewing posts 1–8 of 8

hi,
i would like to ask if it is possible to get the latest posts based on the update date and not the created date.
for example, if i created a post on the 1st of june, i would like it to show always the 1st june as the creation date but if i made a change on 7 june inside it, i would like it to go over a post created on 5 june. important, it would be perfect if i had the ability to tell each post that the change i made at it, it is worth to be marked as an update. because if i would just go inside that post to correct a typography mistake, i wouldn't like the post to go over the other posts just because of that. so there would be perfect if there would be an option for that.
thank you very much

Hi there,

you can add the PHP Snippet provided here:

https://docs.generatepress.com/article/generate_post_date_show_updated_only/

This will display ONLY one date ... if the post hasn't been updated it will show the published date, if the post has been updated it will show the Updated date.

Regarding the editor the Theme has no responsibility over the date creation its a WordPress function. Not sure but i found this plugin that allows you to freeze the date:

https://wordpress.org/plugins/change-last-modified-date/

hi david,
1. to understand better, if the post has been updated, it will show the updated day AND being taxonomized by the updated date?
2. very useful plugin
thank you!

1. By default the theme outputs a date line that includes both the Published and Updated (modified) date, one of which is hidden using CSS. That filter will change the date so ONLY one of them is ever output. So yes, with that code if the post has been Updated it will only display the Updated date.

i added the php snippet, i made a change in an older post but it does not show it first.
what did i miss or did wrong? :)
thanks

Hi Nikos,

The filter only changes which date to show, but it won't affect the way that WP orders the posts.

If you want the posts ordered by updated date, try this PHP snippet:

add_action( 'pre_get_posts', function( $query ) {
    if ( $query->is_main_query() && ( $query->is_home() || $query->is_search() || $query->is_archive() )  ) {
        $query->set( 'orderby', 'modified' );
        $query->set( 'order', 'desc' );
    }
} );

Let me know :)

yes that was it !!! thank you Ying !!!

No problem :)

This archived topic is closed to new replies.