Multiple meta_values ​​use the same meta_key to query posts' custom fields
P粉674876385
P粉674876385 2023-08-15 14:16:16
0
1
711
<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粉674876385
P粉674876385

reply all(1)
P粉819533564

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template