Hi,
Thank you for contacting us and I'd be happy to assist.
To restrict the display of the post results in views, based on a custom taxonomy attached to the current user, you'll need some custom code.
Here are the steps that I'll recommend:
1. You'll first need a select type custom user field "Allowed Project".
( example screenshot: select-user-field.png )
Note that this field will only have one default option in the field's settings and the rest of the options will be generated from a custom taxonomy, programmatically.
2. Next, you'll add a custom taxonomy "Projects" and attach it to your post type, which you'd like to control the user access to.
3. To populate the "Allowed Project" user field's options from this new "Projects" taxonomy's terms, you'll need a custom function attached to the "wpt_field_options" filter:
https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options
Example:
add_filter( 'wpt_field_options', 'func_to_dynamically_allowed_projects', 10, 3);
function func_to_dynamically_allowed_projects( $options, $title, $type ){
switch( $title ){
case 'Allowed Projects':
$args = array('hide_empty' => 'false');
$terms = get_terms( array('project'), $args );
foreach ($terms as $term) {
$options[] = array(
'#value' => $term->slug,
'#title' => $term->name
);
}
break;
}
return $options;
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
As a result, all available terms in the "Projects" taxonomy, will be included as options in the "Allowed Project" user field. When a project will be saved in this custom user field, the selected term's 'slug' will be saved as a custom field's value.
4. In the view, where you'd like to only show the posts attached to the project taxonomy term linked to the currently logged-in user, you can include a taxonomy query filter and set it to show only posts linked to the taxonomy term whose 'slug' is passed through the shortcode attribute.
( example screenshot: taxonomy-query-filter-example.png )
5. The last step would be to pass the current user's selected term slug value in the shortcode for the view, using the types fields API shortcode ( [types usermeta='allowed-projects' output='raw' user_current='true'][/types], ref: https://toolset.com/documentation/customizing-sites-using-php/functions/ ).
For example:
[wpv-view name="views-to-show-the-posts" wpvbookproject="[types usermeta='allowed-projects' output='raw' user_current='true'][/types]"]
This way, the view will only return those posts, where the attached taxonomy term is the same as the one saved in the current user's user field "Allowed Project".
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar