[resolved] First letter posts (5 posts)

  1. Matt_NY
    Posted 6 years ago #

    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?


  2. sparky157
    Posted 6 years ago #

    Did you have any luck with this?

  3. MichaelH
    Posted 6 years ago #

    //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().
  4. x00374
    Posted 6 years ago #

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

  5. jt70
    Posted 6 years ago #


    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.


Topic Closed

This topic has been closed to new replies.

About this Topic