I have the following problem.
On my WordPress page there are small sticky posts and one big sticky post, this is all fine. But there are also regular posts and I need to not display the posts that are marked as sticky or big sticky with a meta value.
I need to query for value is not true or doesn’t exist for home_post
key and value is not true or doesn’t exist for big_home_post
key.
The code I came up with is the following:
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'big_home_post',
'value' => true,
'compare' => '!='
),
array(
'key' => 'big_home_post',
'value' => true,
'compare' => 'NOT EXISTS'
),
),
array(
'relation' => 'OR',
array(
'key' => 'home_post',
'value' => true,
'compare' => '!='
),
array(
'key' => 'home_post',
'value' => true,
'compare' => 'NOT EXISTS'
),
),
),
The code is not working.
Maybe the multidimensional array is not built correctly or WordPress doesn’t support this at all.
All help is appreciated
It is not possible to use nested array in meta_query. You need to write your own query for that. I suggest you to following code to achieve your target;
Simply, I have put a control called
custom_meta_query_enabled
. If you set this field in yourWP_Query
to true, system query will be overrided with custom join query. In order to use this, you can put it infunctions.php
Hüseyin BABAL’s answer is outdated. As codex states:
So
meta_query
value like in question would work.Codex: Custom Field Parameters