Created
December 5, 2014 07:26
-
-
Save Clorith/2843d156df053e584393 to your computer and use it in GitHub Desktop.
Get any WordPress post without any tags
This file contains hidden or 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; | |
$entries = $wpdb->get_results( $wpdb->prepare( " | |
SELECT | |
p.ID, | |
t.term_id | |
FROM | |
" . $wpdb->posts . " p | |
LEFT JOIN | |
( | |
SELECT | |
term_rel.object_id, | |
term_rel.term_taxonomy_id, | |
t.taxonomy, | |
t.term_id | |
FROM | |
" . $wpdb->term_relationships . " term_rel | |
JOIN | |
" . $wpdb->term_taxonomy . " t | |
ON ( t.term_taxonomy_id = term_rel.term_taxonomy_id ) | |
WHERE | |
t.taxonomy = %s | |
GROUP BY | |
term_rel.object_id | |
) t | |
ON ( t.object_id = p.ID ) | |
WHERE | |
t.term_id IS NULL | |
AND | |
p.post_type = %s | |
", 'post_tag', 'post' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment