[Support request] Sort by date on Category pages

Home Forums Support [Support request] Sort by date on Category pages

Home Forums Support Sort by date on Category pages

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #632838
    Jonah

    I am trying to get category pages to sort by date, for some reason it still sorts by title. Is there a function I should override? This is the code I am using.

    
    	add_action( 'pre_get_posts', 'my_change_sort_order'); 
        function my_change_sort_order($query){
    		if($query->is_archive() || $query->is_category()):
    			
    			//If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
               //Set the order ASC or DESC
               $query->set( 'order', 'DESC' );
               //Set the orderby
    		   $query->set( 'orderby', 'post_date' );
    		   return;
    
            endif;    
        };
    
    GeneratePress 2.1.3
    #632893
    Tom
    Lead Developer
    Lead Developer

    I think it should be: $query->set( 'orderby', 'date' );

    Let me know 🙂

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