Hmm. I can’t think of an easier way to do this due to that to see what category the post is in, you have to check the posts2cat
table and to find matching posts, you have to query the posts
table.
(And yes, I realize using *
is icky, but we probably need all columns in the table anyway and I’m too lazy to list all the columns out.)
$posts = wpdb->get_results('SELECT * FROM $wpdb->posts WHERE post_title LIKE A% ORDER BY post_title');
foreach ($posts as $post) {
if (wpdb->query('SELECT rel_id FROM $wpdb->post2cat WHERE category_id = X AND post_id = $post->ID') === 0) continue;
else {
echo 'this is a post that starts with "A" and is in cat ID #X';
}
}
(rel_id
doesn’t matter, it was just picked at random. We just gotta query for something. COUNT
would work too.)
An easier way to do this might to be putting all posts starting with the letter “A” in a category of their own.