Home › Forums › Add-ons › Repeater Field › Repeater Plugin – Group By Help › Reply To: Repeater Plugin – Group By Help
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.