Last active
August 29, 2015 14:04
-
-
Save mohamedrez/ceeae8f33236b6510901 to your computer and use it in GitHub Desktop.
wp: select all metadata values
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
<?php | |
function get_meta_values( $key = '', $type = 'post', $status = 'publish' ) { | |
global $wpdb; | |
if( empty( $key ) ) | |
return; | |
$r = $wpdb->get_col( $wpdb->prepare( " | |
SELECT pm.meta_value FROM {$wpdb->postmeta} pm | |
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id | |
WHERE pm.meta_key = '%s' | |
AND p.post_status = '%s' | |
AND p.post_type = '%s' | |
", $key, $status, $type ) ); | |
return $r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment