• Hi,
    i have, for example arry of those strings
    array("643","London","foo")
    and I’d like to add another meta_query member searching for every post, that have any of this string in any of his meta. Is there any way to do it?

    something like

    array(
       "value" => array("643","London","foo"),
       "compare" => "LIKE" )

    but this don’t work obviously, cause only string can be in “value”.

    Thanks in advance for any hint ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • ‘value’ can be an array if you change ‘compare’ to ‘IN’.

    Thread Starter chlustanec

    (@chlustanec)

    Hi, thanks for reply.
    That’s what I’ve end up with so far. But it is not kind of the same, because when u use LIKE, it searsech %value% with wildcards. When you have IN, it searches exact VALUE. And even if I send %value% to IN comparison, it does not work.

    Since I can’t see your entire args, you will need to modify the code below. You can use multiple entries in a meta_query with an ‘OR’ relation:

    $args = array(
    	'post_type' => 'product',
    	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    			'key' => 'the key',
    			'value' => '543',
    			'compare' => 'LIKE'
    		),
    		array(
    			'key' => 'the key',
    			'value' => 'London',
    			'compare' => 'LIKE'
    		)
    		array(
    			'key' => 'the key',
    			'value' => 'foo',
    			'compare' => 'LIKE'
    		)
    	)
    );
    Thread Starter chlustanec

    (@chlustanec)

    Hi, thanks.
    That’s my fault, I should have pst the args in the first post. Thing is, I have args like this

    $args = array(
    	'post_type' => 'product',
    	'meta_query' => array(
    		'relation' => 'AND',
    		array(
    			'key' => 'number',
    			'value' => array(1, 1000),
    			'compare' => 'BETWEEN'
    		),
    		array(
    			'key' => 'county',
    			'value' => array('OC','CO'),
    			'compare' => 'IN'
    		),
                    ...,
    		array(
    // AND there I need what I asked for, so something like.
    			'relation' => 'OR',
                            array(...LIKE...),
                            array(...LIKE...),
                            array(...LIKE...)
    		)
    	)
    );

    Args in the begining are from inputs like dropdown, multiselect, radio and numeric inputs (so the inputs are exact), but the last part of query is “fulltext” input of words divided with “,” and I wanted to assure, that I eliminate some of human mistakes during input of text strings (so I wanted to use wildcards = LIKE comparison).

    Maybe I am approaching it from completely wrong way, so If somebody knows prettier, better or working way, you are welcome to throw me some hint ??

    I don’t think you will be able to do this with query_posts args. I believe that you will need to build up the sql for the query or use a filter to add to the query.

    Thread Starter chlustanec

    (@chlustanec)

    that is what was affraid of ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘metaquery with array of values’ is closed to new replies.