I have a custom post type called "Property". In it I have some custom fields, built via the Advance Custom Fields plugin. One of the fields I built is a "select" field (pulldown) that has all 50 US states in there, the field name is 'state_prop'. What I need to do is have a list of each state and the quantity of how many posts each state is used in.
So if I have 100 total "Property" posts, how many are for Texas, how many for Illinois, etc. I can get a count for individual states by doing this:
$count = array('post_type' => 'Property', 'meta_key' => 'prop_state', 'meta_value' => 'Illinois');
$myquery = new WP_Query($count);
echo "<p>Found: $myquery->found_posts</p>";
But that's not very elegant because I would have to run that code 50 times, one for each state. I'm worried that would put too much strain on the server if it had to run all 50 time and time again.
I found some code that gets me closer with, but I don't know how to get the counts. I know I'll need to put all 50 states into the 'value', but how do I get them to echo out? The whole array inside an array thing baffles me:
$counteach = array( 'post_type' => 'Property', 'meta_query' =>
array( 'key' => 'prop_state', 'value' => 'Texas', 'Illinois'),
Is there a simpler way of doing what I want? Thanks for your help. When I signed up with WPMUDEV I remember reading something about "ask us any Wordpress question", so that's why I'm asking even though this has nothing to do with your plugins.