I recently started using simple fields on a project to differentiate between types of posts. All posts from now on will have one of four possible meta values associated with this (Story, Article, Video or Cartoon). None of these types of posts have unique attributes or values, so I’ve decided not to go the custom post type route this time.
I’m aware how to query for posts with a certain meta value, but this only works on posts that already have that meta key associated with them – not for posts that were created before the simple fields plugin was installled, and put into use. I’m curious how I would query for all posts that either lack the meta key “fizzbuzz” or have the key but it’s associated with a value of “foobar”.
Is there a way to query for all posts that lack a key altogether?
This will get you everything that doesn’t have the meta key fizzbizz. The custom loop part, I lifted directly from the codex.
This will get everything where it’s got the key, but the value is ‘foobar’
and that last one is tricky, I’m not so sure on that one…
Edit
Fixed first query thanks to this question.