Skip to content
Public Ticket #17819

Changing last posts' order to last update

Conversation thread

LazyBit replied

Customer Reply

Works good, thank you!

PenciDesign Supporter replied

Staff Reply

Hi,

Please install the Code Snippet plugin then create a new snippet with the following content:

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

Regards,
PenciDesign.

LazyBit replied

Customer Reply

Hi,

As far as I can see that option just change which info is displayed. I would like posts to be sorted by modified date (last update) instead of by publish date.

PenciDesign Supporter replied

Staff Reply

Hi,

You can change this via Appearance → Customize → General → General Setting, check Display Modified Date Replace with Published Date.

Regards,
PenciDesign.


LazyBit started the conversation

Conversation Start

Hi dev,

I would like to change last posts' sorting from published to modified on home and category pages. Can be done without using any plugin?

Want to join this conversation or access attachments? Sign in first.