Home  >  Q&A  >  body text

Multiple meta_values ​​use the same meta_key to query posts’ custom fields

<p>Scenario: Posts have multiple entries with values ​​for the same key, for example a single post will have multiple meta_key [drink] => meta_value</p> <pre class="brush:php;toolbar:false;">[drink] => "Banana Juice" [drink] => "Orange juice" [drink] => "apple juice"</pre> <p>Want to find: posts that do not have an orange value in any entry with meta_values ​​with the same meta_key as drink. </p> <p>Current method: using wp_query: </p> <pre class="brush:php;toolbar:false;">meta_query => array(array('key' => 'drink','value' => 'orange','compare' => ; 'NOT LIKE'));</pre> <p>Question: wp_query will still return posts with meta_value "orange" because it has other [drinks] with values ​​that are not "orange". </p>
P粉674876385P粉674876385431 days ago667

reply all(1)I'll reply

  • P粉819533564

    P粉8195335642023-08-16 10:48:07

    In SQL wildcard searches , you need to use the value %orange% in NOT LIKE.

    does not have the % wildcard, and NOT LIKE has the same meaning as <> or NOT EQUAL.

    reply
    0
  • Cancelreply