Created
August 3, 2010 11:46
-
-
Save christiangun/506224 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 is for Wordpress and will get post data from posts | |
* that are associated with a specific meta key and meta value pair. | |
* | |
* By: Christian Gundersson, christian@buro2.se | |
* | |
*/ | |
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