Support » Fixing WordPress » First letter posts

  • Resolved Matt_NY


    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?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Did you have any luck with this?

    //get all post IDs for posts beginning with cap B, in title order,
    //display posts
    $first_char = 'B';
    SELECT      ID
    FROM        $wpdb->posts
    WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
    ORDER BY    $wpdb->posts.post_title",$first_char)); 
    if ($postids) {
      '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>
    wp_reset_query();  // Restore global post data stomped by the_post().

    Thanks for code MichaelH, but where should I post it? in post.php?


    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.


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘First letter posts’ is closed to new replies.