Hello, I am having some trouble with a second layer of filtering. I can't figure it out.
First, I have a custom post type (staff portal pages) with 2 custom taxonomies (staff portal categories and staff portal access types).
I have custom user meta that assigns a user 1 or many staff types (all staff, admin, team leads, dvm, and support staff).
I will have the same 5 staff types mirrored in the staff portal access types taxonomy.
When a user of a specific staff type logs in, their dashboard will have the view that feeds posts that are matched to their access type.
So, if a user with all staff, and team leads logs in, the posts that have those access types selected in the custom taxonomy will be visible.
My code works if I am only feeding the posts via a single view, but when I try to first filter by the other taxonomy, my code breaks.
add_filter( 'wpv_filter_query', 'func_prefilter_food_drink_taxonomy', 99, 3 );
function func_prefilter_food_drink_taxonomy( $query_args, $view_settings, $view_id ) {
$current_user = wp_get_current_user();
$current_user_login = $current_user->user_login;
$current_user_id = $current_user->ID;
$current_user_meta = get_user_meta($current_user_id, 'wpcf-portal-staff-type', true);
$staff_type_array = array($current_user_meta['wpcf-fields-checkboxes-option-1bc875802f7cd80318e2856c04d94805-1']['0'],$current_user_meta['wpcf-fields-checkboxes-option-758fcce84fcd4ce43714086c8197e782-1']['0'],$current_user_meta['wpcf-fields-checkboxes-option-665cd1c9a2322706e21ef5eeb53fc9b9-1']['0'],$current_user_meta['wpcf-fields-checkboxes-option-343b76173c6607890afa154a6f35b4b7-1']['0'],$current_user_meta['wpcf-fields-checkboxes-option-b6e731fe3a431f47c6cb723d4bfe24b3-1']['0']);
$display_view_ids = array(3217);
if (in_array($view_id,$display_view_ids) and empty($query_args['tax_query']) ){
$query_args['tax_query'] = array(array(
'taxonomy'=> 'staff-portal-access-type',
'field' => 'slug',
'terms' => $staff_type_array,
'operator' => 'IN',
'include_children' => 1
));
}
return $query_args;
}
You will see that I created an array of staff types that are being pulled by the current user. This feeds the tax_query only the terms that the current user has assiciated to them.
This works perfectly.
However, I want the posts to be broken up by the other category, so each posts of that category is under a nice title.
I tried filtering the posts by the taxonomy filter, and then putting the view id of the taxonomy filter into my code, but that doesn't work.
I hope I explained myself well.
Please let me know what I am doing wrong.
Thanks!