Scenario:
Posts have multiple entry of values with the same key, example a single post will have multiple meta_key [drink] => meta_value
[drink] => "banana juice"
[drink] => "orange juice"
[drink] => "apple juice"
Want to find: Posts without value of orange in any entry of the meta_values with the same meta_key drink.
current method: using wp_query:
meta_query => array(array('key' => 'drink','value' => 'orange','compare' => 'NOT LIKE'));
Issue:
wp_query will still return post with meta_value "orange" in [drink] because it has other [drink] with values which is not "orange".
2
Answers
I have found the answer by doing 2 wp_query (1 to get all the relevant posts and 1 to get all the post that has the orange drink) and do an array_diff to get the post without the orange drink.
Sample Code:
In the goofy world of SQL wildcard searches you need to use a value of
%orange%
with NOT LIKE.Without the
%
wildcards NOT LIKE means the same thing as<>
or NOT EQUAL.