Wordpress meta_query LIKE compare values ​​from array

I have a script that looks like this:

  foreach($target_zips as $zipcode) {

      $query_adresses = array (
        'order'     => 'ASC',
        'cat'       => $_GET["cat"],
        'post_type'=> 'adressen',
        'posts_per_page'   => '-1',
        'meta_query' => array(
            array(
                'key'     => 'postcode',
                'value'   => $zipcode,
                'compare' => 'LIKE',
            )
        )
      );

      $results = get_posts( $query_adresses );

      $matched_adresses[] = $results;

  }

      

A script that walks through an array of values ​​then queries a lot of posts to see if there are records that match the meta_query. It's awfully slow. Is it possible to put an array of values ​​into this meta_query instead of querying over and over for each value in $target_zips

?

+3


source to share


1 answer


Replace 'compare' => 'LIKE'

, with 'compare' => 'LIKE'

, because after, (comma)

try it



 array(
      'key'     => 'postcode',
      'value'   => $zipcode,
      'compare' => 'LIKE'
     )

      

-2


source







All Articles