Created
January 7, 2012 03:35
-
-
Save mhlipson/1573694 to your computer and use it in GitHub Desktop.
Query WordPress Posts without a custom meta key
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 | |
global $wpdb; | |
$meta_key = ''; // Enter your meta key | |
$querystr = "SELECT $wpdb->posts.ID | |
FROM $wpdb->posts | |
WHERE $wpdb->posts.post_status = 'publish' | |
AND $wpdb->posts.post_type = 'post' | |
AND $wpdb->posts.ID NOT IN ( | |
SELECT $wpdb->posts.ID | |
FROM $wpdb->posts | |
left join $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) | |
WHERE $wpdb->posts.post_status = 'publish' | |
AND $wpdb->postmeta.meta_key = '".$meta_key."' | |
)"; | |
$pageposts = $wpdb->get_results($querystr, OBJECT); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment