Does this look correct? I’m getting good results with it. So, i think i got it.
$plfsByState = $wpdb->get_results($wpdb->prepare( " SELECT pm.meta_value as state, count(*) as postcount FROM $wpdb->posts p join $wpdb->postmeta pm on p.ID = pm.post_id where p.post_type = 'plfmaps' and p.post_status = 'publish' AND meta_key LIKE %s AND meta_value LIKE %s GROUP BY meta_value ASC", 'locations_%_state', '%', "" ));
Thanks for your help. This appears to be showing all of the states, grouped by the state and then showing a count of the total number of results from that state. This is a little tricky with those % signs.
Question about the query. At the very end, ‘locations_%_state” is the meta_key, and ‘%’ is the meta_value, so then what is the “” at the very end? What does that do?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.