How Do I Order Posts by Modified Date? [duplicate]

I’ve read the codex article about WP_Query‘s orderby parameters and I understood that it is possible to order by Modified date. But I couldn’t find where should I edit.

How WordPress post order by modified date including home page as well as categories page and tag pages?

3 Answers
3

Try this:

function my_custom_ordering( $query ) {
    if($query->is_main_query() AND !is_admin() ) {
      if ( $query->is_home() ||  $query->is_category() ||  $query->is_tag() ){
            $query->set( 'orderby', 'modified' );
       }
   }
}
add_action( 'pre_get_posts', 'my_custom_ordering' );

This will set orderby field to modified in the WordPress query.

Leave a Comment