Sorting Posts | Alphabetical Order

Have you read this thread? Display all posts starting with given letter?

This wouldn’t be simple to do with WP_Query and that’s unfortunate because that would help preserve pagination.

// Rules
$args = ['post_type'=>'post','orderby'=>'name'];

// The Query
$query1 = new WP_Query( $args );

// The Loop
while ( $query1->have_posts() ) {
    $query1->the_post();
    echo '<li>' . get_the_title() . '</li>';
}

You could use wpdb

global $wpdb;
$results = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_title LIKE 'B%';", ARRAY_A );

& then use WP_Query

// Rules
$args = ['post_type'=>'post','post__in'=>$results];

// The Query
$query1 = new WP_Query( $args );

// The Loop
while ( $query1->have_posts() ) {
    $query1->the_post();
    echo '<li>' . get_the_title() . '</li>';
}

pre_get_posts() is another good one to use when doing this kind of thing.

error code: 523