Home › Forums › General Issues › Get DISTINCT values for all posts › Reply To: Get DISTINCT values for all posts
I’m looking for this as well. I found a solution here: https://stackoverflow.com/a/20293486/1766219
Note, that there is typo on that solution, which I have corrected in below-written solution:
global $wpdb; // (this is required when are you inside the function)
$values = $wpdb->get_results("SELECT DISTINCT meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key = 'NAME_OF_THE_FIELD_YOURE_AFTER' and pm.post_id=p.ID and p.post_type='CUSTOM_POST_TYPE_NAME' ",ARRAY_A);
print_r($values);
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.