• I am trying to build a query that checks the contents of an array against a meta_key and for some reason I can’t get it to select the values in the array. Everything else works, just not the part that I need to compare against the array string.

    I have an array with a list of variations on the possible names of the community:

    $community_name_variations = array('AB Condo','The AB','Condo A B')'

    I need one of those values to match the meta_key MLS_SUBDIVISION exactly.

    Then I load the argument with the above array:

    $args = array(
         'posts_per_page' => 10,
         'post_type' => 'mls',
         'meta_query' => array(
              'relation' => 'AND',
                   array(
                         'meta_key' => 'MLS_SUBDIVISION',
                         'value' => array(''.$name_variations.''),
                         'compare' => 'IN')
                   ),
                   array(
                        'meta_key' => 'MLS_ZIP_CODE',
                        'value' => '33480',
                        'compare' => '='),
                   array(
                        'meta_key' => 'MLS_PROPERTY_TYPE',
                        'value' => 'A',
                        'compare' => '='),
                   array(
                        'relation' => 'OR',
                             array(
                                  'meta_key' => 'MLS_STATUS',
                                  'value' => 'ACTIVE',
                                  'compare' => '='),
                             array(
                                  'meta_key' => 'MLS_STATUS',
                                  'value' => 'CONTIGNENT',
                                  'compare' => '=')
    			)
    		),
         'orderby' => 'date',
         'order' => 'DESC',
    );

    If I run this query everything works except the MLS_SUBDIVISION portion.

    I’ve also tried the following with no success:

    array(
                         'meta_key' => 'MLS_SUBDIVISION',
                         'value' => array('AB Condo','The AB','Condo A B'),
                         'compare' => 'IN')
                   ),

  • The topic ‘meta_query check meta_key against array’ is closed to new replies.