Sorting options for category pages

Posted in: Newsmag
Post count: 104

Is there a way to show posts sorted through their name instead of post id when viewing a category page?

Post count: 1291

Hi,

Add the following code – http://screencast.com/t/IRBVWGV7

if (is_category()){
$args['orderby'] = 'title';
$args['order'] = 'asc';
}

And this one – http://screencast.com/t/ZLtG18fKOHF

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

Thank you, Emil G.

  • This reply was modified 11 years by Emil G.
Post count: 104

Thank you Emil- that worked.

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newsmag’ is closed to new topics and replies.