In search of a technique to nest AND/OR relation in meta_query based mostly on array serialized values.
Reviewed these already:
Question a number of meta key values?
WP Meta Question for some meta (array) values
I perceive that the serialized knowledge ‘shouldn’t’ be used to look/filter (or first must be pulled out to take action outdoors the SQL) BUT I wish to put it on the market so see if nesting might do the trick.
E.g. Information [ meta_value field1 = ‘abc’ , meta_value field2 a:2:{i:0;s:1:”1″;i:1;s:1:”4″;} ]
This holds the values [ “1”, “4”] as string array.
The search I wish to carry out is one thing like
$metaSearchQuery = [
'relation' => 'AND',
[
'key' => '<FIELDNAME1>',
'value' => 'abc'
],
[
'relation' => 'OR',
[
'key' => '<FIELDNAME2>',
'value' => serialize(strval(1)),
'compare' => 'like',
],
[
'key' => '<FIELDNAME2>',
'value' => serialize(strval(4)),
'compare' => 'like',
],
...............
]
];
With the output SQL one thing like
... the place meta_value.field1 = 'abc' and (field2 like 's:1:"1"' or field2 like 's:1:"4"')
That manner you could possibly use the principle ‘AND’ situation for different fields and nest ‘OR’ for array values…?
Is that this even doable utilizing meta_query?
The reason being that I do must filter and the values may very well be 1, 2, 3, 4 or any mixture of there.
Taxonomy higher , sure however this has been written already so wish to utilise the meta construction if doable.