get(‘post_type’) !== ‘post’) {
return;
}
$tax_query = $query->get(‘tax_query’);
if (!is_array($tax_query)) {
$tax_query = array();
}
$research_cat_id = 492;
$has_category_query = false;
foreach ($tax_query as $tq) {
if (is_array($tq) && isset($tq[‘taxonomy’]) && $tq[‘taxonomy’] === ‘category’) {
$has_category_query = true;
break;
}
}
if ($has_category_query || $query->get(‘cat’) || $query->get(‘category_name’)) {
$new_tax_query = array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => ‘category’,
‘field’ => ‘term_id’,
‘terms’ => array($research_cat_id),
‘operator’ => ‘IN’,
)
);
if (!empty($tax_query)) {
unset($tax_query[‘relation’]);
$new_tax_query[] = $tax_query;
}
$cat = $query->get(‘cat’);
if ($cat) {
$cat_ids = array_filter(array_map(‘intval’, explode(‘,’, $cat)));
if (!empty($cat_ids)) {
$new_tax_query[] = array(
‘taxonomy’ => ‘category’,
‘field’ => ‘term_id’,
‘terms’ => $cat_ids,
‘operator’ => ‘IN’,
);
$query->set(‘cat’, ”);
}
}
$query->set(‘tax_query’, $new_tax_query);
}
}



