Title: First letter posts
Last modified: August 19, 2016

---

# First letter posts

 *  Resolved [matt_ny](https://wordpress.org/support/users/matt_ny/)
 * (@matt_ny)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/first-letter-posts/)
 * Hi everyone!
 * How can I show posts on specific page, which are starts (post title) on some 
   letter? For example, I want to show posts only started on letter “B”.
 * Is it possible to do, without writing this letter in custom fields every time
   I publish a new post?
 * Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [sparky157](https://wordpress.org/support/users/sparky157/)
 * (@sparky157)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/first-letter-posts/#post-1316645)
 * Did you have any luck with this?
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/first-letter-posts/#post-1316646)
 *     ```
       <?php
       //get all post IDs for posts beginning with cap B, in title order,
       //display posts
       $first_char = 'B';
   
       $postids=$wpdb->get_col($wpdb->prepare("
       SELECT      ID
       FROM        $wpdb->posts
       WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
       ORDER BY    $wpdb->posts.post_title",$first_char)); 
   
       if ($postids) {
       $args=array(
         'post__in' => $postids,
         'post_type' => 'post',
         'post_status' => 'publish',
         'posts_per_page' => -1,
         'caller_get_posts'=> 1
       );
       $my_query = null;
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
        echo 'List of Posts Titles beginning with the letter '. $first_char;
         while ($my_query->have_posts()) : $my_query->the_post(); ?>
           <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
         endwhile;
       }
       wp_reset_query();  // Restore global post data stomped by the_post().
       }
       ?>
       ```
   
 *  [x00374](https://wordpress.org/support/users/x00374/)
 * (@x00374)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/first-letter-posts/#post-1316662)
 * Thanks for code MichaelH, but where should I post it? in post.php?
 *  [jt70](https://wordpress.org/support/users/jt70/)
 * (@jt70)
 * [16 years ago](https://wordpress.org/support/topic/first-letter-posts/#post-1316670)
 * MichaelH,
 * Thanks for all the support you give. I’ve seen your name around this forum.
 * One question on your code before I try it. How would I go about only showing 
   posts from a specific category. I think I could muddle through with an ‘if’ statement,
   but wondered if there might be a more efficient way. I’m trying to replace the
   AZIndex function with something less query intensive.
 * Thanks.
    JT70

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘First letter posts’ is closed to new replies.

## Tags

 * [first letter](https://wordpress.org/support/topic-tag/first-letter/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 5 participants
 * Last reply from: [jt70](https://wordpress.org/support/users/jt70/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/first-letter-posts/#post-1316670)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
