I am trying to: filter 'views' and 'archive views' using cookie values set by user's preference.
The website has two drop downs on top left which allows user to search for 'city' and 'age-group' preferences. These values are saved in cookies and later used to filter the various views using wpv_fiter_query option.
'cities' and 'age-groups' are custom taxonomies.
Various 'views' work as expected.
But 'Archive' view (view id: 52819) does not seem to work. It does not honor age-group filtering.
Here is the code used:
add_filter( 'wpv_filter_query', 'ksp_events_home', 999, 3 );
function ksp_events_home( $query_args, $view_settings, $view_id ) {
$_apply_filter_view = array("77962","52363","52317","65094","52084","52819","55779","53165","55707","58595");
if (in_array($view_id,$_apply_filter_view)) {
global $_curr_user_city,$_curr_user_age; //echo $_curr_user_city."<==>".$_curr_user_age;
if(!empty($_curr_user_city) || !empty($_curr_user_age)){
if(!empty($_curr_user_city)){
$query_args['tax_query'][] = array(
'taxonomy' => 'city',
'field' => 'term_id', //term_id
'terms' => array($_curr_user_city),
'operator' => 'IN',
'include_children' => 1
);
}
if(!empty($_curr_user_age)){
$_curr_user_ageArr = explode(",",$_curr_user_age);
$query_args['tax_query'][] = array(
'taxonomy' => 'age-group',
'field' => 'term_id',
'terms' => $_curr_user_ageArr,
'operator' => 'IN',
'include_children' => 1
);
}
$query_args['tax_query']['relation'] = 'AND';
}
}
return $query_args;
}
The programming team has written following function that seems to work
I visited this URL:
hidden link
Select age group : 4-6 years from the header top left drop down.
The post: 'Easy to make, healthy snacks for baby's daycare' should not show up.
Are we missing something in our code. Your help in the matter will be highly appreciated.
For your reference: Attached screenshot shows that the post Easy to make, healthy snacks for baby's daycare' does not belong to 4-6 years category. However, it still shows up.
Your help in the matter will be highly appreciated.