Selecting posts with a given meta value for a meta key

This works although I have no idea why this and not that. Would like to see an explanation in an answer.

Because that code sets the posts_per_page value to -1 which means no limit and it’s similar to setting nopaging to true, hence all found posts are returned.

it reports finding all the posts with a post count of 7 (there are 21 posts)

I think the original issue here is that you probably not aware that the property $post_count (i.e. WP_Query::$post_count) is actually the number of posts just for the current page, so if LIMIT was used (in the SQL statement generated by WP_Query), e.g. by setting the posts_per_page value to, say, 10 which is the default value, then the $post_count would be 10 or less depending on the total number of posts in the database which matched the specific query.

So if you want to get that total number, then use the $found_posts property:

$my_query = new \WP_Query( array(
    'posts_per_page' => 1, // just for testing
) );

echo "Number of posts with LIMIT applied: {$my_query->post_count}<br>";

echo "Number of posts without LIMIT applied: {$my_query->found_posts}";

See here if you’d like to check the other properties in WP_Query.

Additional Notes

  1. If you don’t set the posts_per_page in your query args, the value will default to 10 or whatever you put in the “Blog pages show at most” input on the Reading Settings admin page (wp-admin → Settings → Reading). And I guessed you had it set to 7?

  2. I think that "{$raw_perma}" could simply be written as $raw_perma as in 'meta_value' => $raw_perma and 'value' => $raw_perma .. 🙂