Archived topic
posts ordered by last modified date
4 replies · Started by Xiaowei on March 7, 2019
function wzj_order_by_last_modified( $query ) {
if($query->is_main_query() AND !is_admin() ) {
if ( $query->is_home() || $query->is_category() || $query->is_tag() ){
$query->set( 'orderby', 'modified' );
$query->set( 'order', 'DESC' );
}
}
}
add_action( 'pre_get_posts', 'wzj_order_by_last_modified' );
Above code doesn't work, I'm not sure if it's GeneratePress or myself missing something.
Hi there,
the code looks ok.
I think the problem is that your posts do not have any modified date applied, there is not meta tags for these in the posts
The posts do have modified date applied, I queried wp_post table.
My bad, I ticked a post as featured and stick to the top. That's why sorting by last modified didn't work.
Aah good find - thanks for reporting back. Glad you got it resolved.