Order Posts Alphabetically in WordPress Posts Archives

By default, WordPress auto-sorts posts according to the date it was created. If you want to sort posts according to Alphabetical Order, use the below code in your child theme’s functions.php

/* Order WordPress Posts Alphabetically */
function wpflt_order_posts_alphabetically_archive ( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' );
    }}
add_action( 'pre_get_posts', 'wpflt_order_posts_alphabetically_archive' );