Thank you for waiting.
Here are the steps, that I'll recommend for restricting access to the single "Артели" post pages ( e.g. hidden link ), so that only the users who have a related "ВОЛШЕБНИК" post attached to it, can view it.
1. The "Артель" content template is set to show the regular content on the single "Артели" post pages. But, you'll create a new content template named something like "Not allowed" so that it is shown to the users who are not allowed access.
You can add any message in this template like "You're not allowed to view this page" etc and you don't have to assign this page to any post type.
2. Next, you'll need a custom function attached to the "wpv_filter_force_template" filter, which will decide whether to show the regular "Артель" content template or the "Not allowed" content template, based on the current user:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template
Example:
add_filter( 'wpv_filter_force_template', 'prefix_restrict_Артель_template', 101, 3 );
function prefix_restrict_Артель_template( $template_selected, $id, $kind ) {
if($kind == 'single-artel') {
$not_allowed_template_id = '12345';
$current_user_id = get_current_user_id();
if ( $current_user_id == 0 ) {
$template_selected = $not_allowed_template_id;
}
else
{
$args = array(
'post_type' => 'volshebnik',
'posts_per_page' => -1,
'post_status' => 'publish',
'author' => $current_user_id,
'fields' => 'ids'
);
$posts_array = get_posts( $args );
if (!empty($posts_array)) {
$related = array();
foreach ($posts_array as $posts_array) {
$related_parent = toolset_get_related_post( $posts_array, 'volshebnikiartelya', 'parent' );
if($related_parent == $id) {
$related[] = $related_parent;
}
}
if(empty($related)) {
$template_selected = $not_allowed_template_id;
}
}
else
{
$template_selected = $not_allowed_template_id;
}
}
}
return $template_selected;
}
Note: Please replace '12345' with the actual ID of the newly created "Not allowed" content template.
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.
After this code has been added, non-logged in guests and the user's who are not linked to the current "Артели" post, will see a "not allowed" message, while the users who are linked to the current "Артели" post, will see the regular content.
I hope this helps and please let me know if you need any further assistance around this.