Support

Account

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);