List posts alphabetically | WordPress.org

[ad_1]

I thought I have solved it, but I have partly figured it out. When the page loads the first time, all posts are displayed alphabetically, but when I click on a category, not any more.

If I click “Show All” after clicking category, posts are not displayed alphabetically either. This is the code I used:

function foo_modify_query_order( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( ‘orderby’, ‘title’ );
$query->set( ‘order’, ‘ASC’ );
}
}
add_action( ‘pre_get_posts’, ‘foo_modify_query_order’ );

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer