Created
December 27, 2012 08:03
-
-
Save jorijn/4386456 to your computer and use it in GitHub Desktop.
get_unique_meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* returns an array of unique items of meta_value, this was originally | |
* built for a filter machanism. | |
* | |
* @param string $post_type example: post | |
* @param string $meta_key example: _wp_page_template | |
* @return array | |
*/ | |
function get_unique_meta($post_type, $meta_key) | |
{ | |
global $wpdb; | |
$prepare = $wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta m INNER JOIN $wpdb->posts p ON (m.post_id = p.ID) WHERE p.post_type = %s AND meta_key = %s ORDER BY meta_value ASC", $post_type, $meta_key); | |
$result = $wpdb->get_results($prepare); | |
$return = array(); | |
foreach ((array)$result as $item) | |
{ | |
$return[] = $item->meta_value; | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment