In each category there is one special post with a meta key called 'overview' ('overview' = 'true'). When a category is selected we get all posts in the category, including the overview item and all post in the child categories including their 'overview' items. I want to use pre_get_posts to filter out the 'overview' items for all the child categories, but keep the overview of the actual category i have selected.
I can set a meta_query filter (with one or more conditions), but how do i include a standard field query at the same time. [Categories are a bit strange anyway as they are not a simple field, if i understand it correctly].
This is part of a larger function which is in the pre_get_posts, add_action.
<?php
if ($query->is_category()) {
// remove overview items for categories other than the one selected
$queried_object = get_queried_object();
$this_cat = $queried_object->term_id;
$meta_query['excl_child'] = array(
'relation' => 'OR',
// the first of the two arrays that follow is where I need some help
array(
'key' => 'cat',
'compare' => '=',
'value' => $this_cat
),
array(
'key' => 'overview',
'compare' => '!=',
'value' => 'true'
);
$query->set('meta_query',$meta_query);
}
The logic is that if the post is either NOT an overview OR is in the actual category selected then it should be included.
(I thought about using post__in to add the specific post by number after specifying a meta_query. Is this an option and what would the code to find the post_ID for that be, please?)