How to query for multiple meta key values with the same key i have this query but multiple value not working for me, Where is my code wrong?

if( isset( $_POST['scheduled_scan'] ) && $_POST['scheduled_scan'] == 'on' )
        $args['meta_query'][] = array(
            'key' => 'antivirus_antivirus_featured_scaning',
            'value' => array('scheduled_scan','anti_spyware','anti_worm'),
            'compare' => 'LIKE'

this is a full code in my form and query if you need

i used the advanced custom fields for keys

thanks for any help.

  • You can't use LIKE with an array of multiple values. What does the value of antivirus_antivirus_featured_scaning look like? Jul 17, 2020 at 9:06
  • antivirus_antivirus_featured_scaning is a checkbox field and i tried with '=' but not work i used advanced custom fields plugin
    – Asadiy4n
    Jul 17, 2020 at 9:11
  • This query will be quite slow, if antivirus_antivirus_featured_scaning had been a custom taxonomy then this query would see massive performance gains, as well as free archives and templates for thse terms. If you're using ACF then it's a simple switch to tell ACF those fields are saved as terms in a custom taxonomy
    – Tom J Nowell
    Jul 17, 2020 at 9:31
  • @TomJNowell how to do ?
    – Asadiy4n
    Jul 17, 2020 at 9:35
  • I answered your other question, but you didn't ask about performance in this question, I won't derail the comments or post an unrelated answer here. You'll need to consult the ACF documentation for how to use taxonomies instead of post meta for a field ( and register a custom taxonomy for it to use to store the data )
    – Tom J Nowell
    Jul 17, 2020 at 9:37

1 Answer 1


This is waaaay after the fact, but maybe it'll help someone else. You're looking for an IN comparison here - where the value is IN a group of values.

Here's what it'd look like:

$args['meta_query'][] = [
    'key' => 'antivirus_antivirus_featured_scaning',
    'value' => ['scheduled_scan','anti_spyware','anti_worm'],
    'compare' => 'IN'

Read more about it here: https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters =]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.