Skip to content

Instantly share code, notes, and snippets.

@timmcdaniels
Created February 28, 2016 21:44
Show Gist options
  • Select an option

  • Save timmcdaniels/b34a828adbf079566210 to your computer and use it in GitHub Desktop.

Select an option

Save timmcdaniels/b34a828adbf079566210 to your computer and use it in GitHub Desktop.
/**
*Get distinct values of custom field from post type
*
*@return void
*@since 0.1
*/
function get_distinct_from_post_type ( $field, $post_type ) {
global $wpdb;
$sql = "SELECT DISTINCT meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key = '$field' AND pm.post_id=p.ID AND p.post_type='$post_type' ORDER BY meta_value";
return $wpdb->get_results( $sql, ARRAY_A );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment