[Resolved] latest posts taxonomy based on update date

Home Forums Support [Resolved] latest posts taxonomy based on update date

Home Forums Support latest posts taxonomy based on update date

  • This topic has 7 replies, 3 voices, and was last updated 1 week ago by Ying.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1818395
    Nikos

    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

    #1818493
    David
    Staff
    Customer Support

    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/

    #1818549
    Nikos

    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!

    #1818639
    David
    Staff
    Customer Support

    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.

    #1819034
    Nikos

    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

    #1819069
    Ying
    Staff
    Customer Support

    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 πŸ™‚

    #1819072
    Nikos

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

    #1819087
    Ying
    Staff
    Customer Support

    No problem πŸ™‚

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