If I get my posts using meta_query by 'my_meta_key' only I get something like this
Array(
[0] => Array(
[nested_key1] => something_I_want1
[nested_key2] => something_I_want2
[dont_care_key] => something_I_dont_care_about
)
[1] => Array(
[nested_key1] => something_I_want1
[nested_key2] => something_I_DONT_want
[dont_care_key] => something_I_dont_care_about
)
)
Now I would like to do a meta_query, that would only fetch posts with 'my_meta_key' containing something_I_want1
AND something_I_want2
at the same time...
Problem is, I can't query by the full array, because a) I really don't care about "something_I_dont_care_about" metas and b) I don't know what they will be - so I need to query only by partial array...
I've tried this without success (WP_Query meta_query arg) (no posts fetched):
'meta_query' => [
[
'key' => 'my_meta_key',
'value' => [
'nested_key1' => 'something_I_want1',
'nested_key2' => 'something_I_want2',
],
'compare' => 'IN', //I've tried with and without
]
],
What am I doing wrong? Is it even possible to query only by part of meta array?
my_meta_key
, can you post a sample? What do you mean with "nested meta key"?my_meta_key
meta is actually an array - I need to test some parts of that array :)my_meta_key
, specially if you prepend the sample code with "I get something like this". Anyway, you shouldn't store arrays in database, maybe PHP serialized arrays in some situations, but never if you need to filter by some of the values inside that array. It will be a very tricky job.LIKE
string search. Maybe this and this can help you.