WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. stoiko
    Member
    Posted 1 year ago #

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

  2. esmi
    Forum Moderator
    Posted 1 year ago #

  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    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