0
votes

I have this piece of code and it works just fine:

$search = array(
    'meta_query'             => array(
        array(
            'key'       => 'wpcf-community-city',
            'value'     => $search_param,
            'compare'   => 'LIKE'
        )
    )
);

But when I change to this, it stops working.

$search = array(
    'meta_query'             => array(
        'relation'      => 'OR',
        array(
            'key'       => 'wpcf-community-city',
            'value'     => $search_param,
            'compare'   => 'LIKE'
        ),
        array(
            'key'       => 'wpcf-community-state',
            'value'     => $search_param,
            'compare'   => 'LIKE'
        ),
        array(
            'key'       => 'wpcf-community-zip',
            'value'     => $search_param,
            'compare'   => 'LIKE'
        )
     )
  );

I'm using Wordpress 3.4.2

PS: This piece of code is a part of the query_posts() parameters.

1
What do you mean by it's not working? Is there an error generated? Does it produce too few results, or too many? Have you tried using the get_sql method to see what SQL it's actually generating? - andrewsi
It's not generating any results, the page gets stuck when it reads this code. - user2777114

1 Answers

0
votes

Why u dont use WP_Query ? U need use the 'relation' parameter ?

Use this example.. its work:

'meta_query' => array(
    array(
    'key' => 'color',
    'value' => 'blue',
    'type' => 'CHAR',
    'compare' => '=' //'=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'
    ),
    array(
        'key' => 'price',
        'value' => array( 1,200 ),
        'compare' => 'NOT LIKE'
    )
),