WordPress supports storing multiple post meta values for a single post using the same meta key. For example one post can have multiple instances of meta_key 'pet' with meta_value 'cat', 'dog', and/or 'fish'. This is super useful when using get_post_meta because you can get an array of all values for the pet meta key, versus managing a serialized array in a single field.
It's also really useful when using a meta query, because you can query any post where meta_key 'pet' = 'cat', and get posts where any instance of 'pet' is equal to 'cat', regardless of how many other instances of the meta key may be associated with the post with different values.
But is the opposite (e.g. !=
or NOT LIKE
or NOT IN
) possible? I'm using the following and it's returning lots of posts that have one instance of meta_key 'pet' = 'cat'.
$pet_owners = new WP_Query([
'post_type' => 'pet_owner',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => 'pet',
'value' => 'cat',
'compare' => '!='
]
]
]);
Edit: I had an error in my pseudocode as flagged by Buttered_toast below.