1

Let's say I have around 2700 posts (assuming 2600 posts starting with letters and 100 Posts starting with numbers. Also there are 100 posts for each letter and number. Like A, B, C, ... have 100 posts each.)

I want to create a page to list posts according to their first letter of their title.

www.website.com/post-lists-Numbers/ shows list of Posts starting with #.
www.website.com/post-lists-A/ shows list of Posts starting with A.
www.website.com/post-lists-B/ shows list of Posts starting with B.
.
.
.
www.website.com/post-lists-Z/ shows list of Posts starting with Z.

I know that for a quick solution to this, I can use this plugin "Alphabetic Pagination"

But I want to learn something new and be able to clear basics and be able to modify custom codes.

Additionally, I want to paginate all the posts, splitting at 50 Posts of each letter in the "letter" page.

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.