Created
August 3, 2010 11:42
-
-
Save christiangun/506221 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* This function will get post data associated with a specific meta key and meta value. | |
* | |
* By: Christian Gundersson, [email protected] | |
* | |
*/ | |
function pcpt_get_posts_by_meta ( $meta_key, $meta_value ) | |
{ | |
global $wpdb; | |
$meta_table = $wpdb->prefix . "postmeta"; | |
$post_table = $wpdb->prefix . "posts"; | |
$sql = "SELECT * FROM " . $post_table . " LEFT JOIN " . $meta_table . " | |
ON " . $meta_table . ".post_id = " . $post_table . ".ID | |
WHERE meta_key = '" . $meta_key . "' | |
AND meta_value = '" . $meta_value . "'"; | |
$post_results = $wpdb->get_results ( $sql ); | |
return $post_results; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment