1. <?php
  2. //get all post IDs for posts beginning with cap B, in title order,
  3. //display posts
  4.  
  5. $first_char = 'B';
  6.  
  7. $postids=$wpdb->get_col($wpdb->prepare("
  8. SELECT ID
  9. FROM $wpdb->posts
  10. WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
  11. ORDER BY $wpdb->posts.post_title",$first_char));
  12.  
  13. if ($postids) {
  14. $args=array(
  15. 'post__in' => $postids,
  16. 'post_type' => 'post',
  17. 'post_status' => 'publish',
  18. 'cat'=>2, //List posts only from category 2
  19. 'posts_per_page' => -1,
  20. 'caller_get_posts'=> 1
  21. );
  22. $my_query = null;
  23. $my_query = new WP_Query($args);
  24. if( $my_query->have_posts() ) {
  25. echo 'Posts that begin with '. $first_char;
  26.  
  27. while ($my_query->have_posts()): $my_query->the_post(); ?>
  28.  
  29. <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
  30. <?php
  31.  
  32. endwhile;
  33. }
  34. wp_reset_query(); // Restore global post data stomped by the_post().
  35. }
  36. ?>