Hello,
I want to create a custom query, which only shows posts that do NOT have a certain meta_key. Is that possible? How?
Thanks!
Hello,
I want to create a custom query, which only shows posts that do NOT have a certain meta_key. Is that possible? How?
Thanks!
I had the same problem over here: http://wordpress.org/support/topic/get_post-query-where-posts-dont-have-a-specific-meta_key-1 I don't think there is a clear solution for this problem so I made a sql query to do this.
Thanks, I guess I'll have to use that. :) Was trying to keep it simple :)
You can also try this before the loop (not tested) :
<?php
$myposts = get_posts('numberposts=-1&meta_key=mykey');
$result = array();
foreach($myposts as $mypost) {
setup_postdata($mypost);
$result[] = $mypost->ID;
}
$args = array(
'post__not_in' => $result
);
query_posts($args);
?>
This gets all the post ID's with the specific meta_key (mykey) and then excludes them from the query.
That's intelligent, but I'm afraid it'll get rather server intensive with a large-ish blog :)
Thanks for the help :)
@keesiemeijer That's a GREAT solution! Thanks for that! It worked right away!
This topic has been closed to new replies.