Created
July 30, 2012 19:35
-
-
Save vc27/3209444 to your computer and use it in GitHub Desktop.
Get post_id from meta_key => meta_value
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
/** | |
* Get post_id from meta_key => meta_value | |
* | |
* @version 0.1 | |
* @updated 07.30.12 | |
* | |
**/ | |
function vc_get_post_id_by_meta__key_value( $meta_key, $meta_value, $limit = 1 ) { | |
global $wpdb; | |
$querystr = "SELECT $wpdb->postmeta.post_id FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' LIMIT $limit"; | |
$results = $wpdb->get_results( $querystr ); | |
if ( isset( $results[0]->post_id ) AND is_numeric( $results[0]->post_id ) ) | |
return $results[0]->post_id; | |
else | |
return false; | |
} // end function vc_get_post_id_by_meta__key_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment