For some reason using pre_get_posts
isn't filtering the products properly on the Shop page. I can tell the hook is being called on the proper page because if I print the $query
variable it only shows on the page I want it to. However, the tax_query
doesn't seem to be filtering properly.
The shop page is set to show categories. I would like to have it where if $_SESSION['mid']
is set, then it will only show that category on the Shop page. I know that the proper value is being passed because I can see it in the print of $query
.
add_action('pre_get_posts','shop_filter_cat');
function shop_filter_cat($query) {
if (!is_admin() && isset($_SESSION['mid']) && is_post_type_archive( 'product' ) && $query->is_main_query()) {
$query->set('tax_query', array( // Include only products from merchant with ID = $_SESSION['mid']
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $_SESSION['mid'],
'operator' => 'IN'
)
)
);
// print_r($query);
}
}
slug
toterm_id
if$_SESSION['mid']
is numeric value'field' => 'term_id'
term_id
and using the category'stag_id
. Still no luck.