[Resolved] posts ordered by last modified date

Home Forums Support [Resolved] posts ordered by last modified date

Home Forums Support posts ordered by last modified date

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #831326
    Xiaowei
    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.

    #831452
    David
    Staff
    Customer Support

    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

    #831461
    Xiaowei

    The posts do have modified date applied, I queried wp_post table.

    #831503
    Xiaowei

    My bad, I ticked a post as featured and stick to the top. That’s why sorting by last modified didn’t work.

    #831505
    David
    Staff
    Customer Support

    Aah good find – thanks for reporting back. Glad you got it resolved.

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