Hi Mike,
Thank you for waiting, while I performed some tests on my own website, with a similar setup.
To dynamically protect the region and state posts, from the people/users of different states, you can make use of the already deployed relationships, without needing the post groups separately.
Note: Due to the complexity involved in this setup, it would be better to use the classic editor and not the blocks editor.
Here are the steps:
1. First, you'll have to make sure that for every registered user on the website, a "People" post exists on the website, where that user is set as the author of that post.
( ref: https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/ )
2. Next, you'll need a post view, which can return the ID of the "state" post, which is connected to the current user's "people" post.
You can name this view to something as "View to get current user's state ID" and set it to show "people" post, where the author is the same as the currently logged-in user.
Example screenshot: lien caché
In the "Loop Wizard" you'll select "List with separators" format, to avoid the extra characters and empty spaces from the output of this view. Please also check the option "Disable the wrapping DIV around the View", just above the "Output Editor" section.
As only the "state" post's ID connected to the current "people" post is needed, you can adjust the content of the "Loop Editor" section to:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-id item="@state-person.parent"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]0[/wpv-no-items-found]
[wpv-layout-end]
You can read about the "item" attribute's usage from https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/
After that, you can use this new view's output in a conditional check to allow or deny access to a particular state's content.
( ref: https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/ )
[wpv-conditional if="( '[wpv-view name='view-to-get-current-users-state-id']' eq '[wpv-post-id]' )"]
You're allowed to view this post!
[/wpv-conditional]
[wpv-conditional if="( '[wpv-view name='view-to-get-current-users-state-id']' ne '[wpv-post-id]' )"]
You're not allowed to view this post!
[/wpv-conditional]
The above conditional block compares the current state post's ID with the ID returned by the view and if they are the same, it shows the allowed message and if they're different, it shows the not allowed message.
This conditional check can be used in the single post Content Template for the state posts and/or inside the post view or WordPress Archive which lists the state posts.
3. Similarly, for a conditional check for "region" posts, you can create a duplicate of your view from the last step and name it to something as "View to get current user's region ID".
Since this view will need to return the ID of the current user's region post, we'll need a third view nested inside this second view, which will get the ID of the region post connected to the specified state's post.
This third view can be named as "View to get region of a state" and you'll set it to show "Regions" posts, with a query filter for the "Regions States" relationship, related to the post whose ID is specified through the shortcode attribute "wpvrelatedto".
Example screenshot: lien caché
Again, in the "Loop Wizard" you'll select "List with separators" format and check the option "Disable the wrapping DIV around the View", just above the "Output Editor" section.
You only need the "region" post's ID from this view and can adjust the content of the "Loop Editor" section to:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-id]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]0[/wpv-no-items-found]
[wpv-layout-end]
Next, in your second view "View to get current user's region ID", you can include the shortcode of this third view in the "Loop Editor" section like this:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-view name="view-to-get-region-of-a-state" wpvrelatedto="[wpv-post-id item='@state-person.parent']"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]0[/wpv-no-items-found]
[wpv-layout-end]
Please note how "[wpv-post-id item='@state-person.parent']" shortcode is used to pass current person's post ID in the "wpvrelatedto" attribute.
After that, you can use this second view's output in a conditional check to allow or deny access to a particular region's content.
[wpv-conditional if="( '[wpv-view name='view-to-get-current-users-region-id']' eq '[wpv-post-id]' )"]
You're allowed to view this post!
[/wpv-conditional]
[wpv-conditional if="( '[wpv-view name='view-to-get-current-users-region-id']' ne '[wpv-post-id]' )"]
You're not allowed to view this post!
[/wpv-conditional]
The above conditional block compares the current region post's ID with the ID returned by the view and if they are the same, it shows the allowed message and if they're different, it shows the not allowed message.
This conditional check can be used in the single post Content Template for the region posts and/or inside the post view or WordPress Archive which lists the region posts.
I hope this helps and please let me know if any point or step is not clear.