Sort post in a category by title, not by date (3 posts)

  1. stoiko
    Posted 3 years ago #

    I need the posts in the category to be sorted by default not by date, but by title.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

  3. Michael
    Forum Moderator
    Posted 3 years ago #


    try to add this to functions.php of your theme:

    function sort_category_archives( $query ) {
        if ( $query->is_category() && $query->is_main_query() ) {
            $query->set( 'orderby', 'title' );
            $query->set( 'order', 'ASC' );
    add_action( 'pre_get_posts', 'sort_category_archives' );

Topic Closed

This topic has been closed to new replies.

About this Topic