• Hello,
    Greetings!!

    I want to use multiple meta query with or relation for more than two conditions like below example:

    $query_args['meta_query'] = array(
    'relation' => 'OR',
    array(
    	'relation' => 'AND',
    	array(
    	'key' => '_job_tags1',
    	'value' => $tagId,
    	'compare' => 'LIKE'
    	),
    	array(
    	'key' => '_job_category1',
    	'value' => $values_serialized,
    	'compare' => 'LIKE'
    	)
    ),
    array(
    	'relation' => 'AND', // make sure only this key exists by matching parameters
    	array(
    	'key' => '_job_tags2',
    	'value' => $tagId,
    	'compare' => 'LIKE'
    	),
    	array(
    	'key' => '_job_category2',
    	'value' => $values_serialized,
    	'compare' => 'LIKE'
    	)
    ),									
    array(
    	'relation' => 'AND', // make sure only this key exists by matching parameters
    	array(
    	'key' => '_job_tags3',
    	'value' => $tagId,
    	'compare' => 'LIKE'
    	),
    	array(
    	'key' => '_job_category3',
    	'value' => $values_serialized,
    	'compare' => 'LIKE'
    	)
    )
    );

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button. Failure to do so makes your code unusable for testing, making it less likely for someone to help you.]

    this above query is not working for me. Anyone can help me?

    Thanks in advance!!

    Regards,
    Pranjali P.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Finding LIKE serialized values can be unpredictable because it becomes a string comparison. Arrays can be equivalent but not match as serialized strings. If your situation is such that this could not cause a problem, proceed to general debugging. The best way to resolve why any particular query is not working is to examine the actual SQL query used. This usually reveals where the problem lies.

    You can get the SQL from the query object. Assuming this is within a WP_Query for posts, the request is saved in WP_Query::request.

    Thread Starter pranjal06

    (@pranjal06)

    Thanks bcworkz for your help!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple or relation meta query is not working for more than 2 queries’ is closed to new replies.