Hi,
Thank you for contacting us and I'd be happy to assist.
If I understand correctly, you'd like to get all the "Contacts Contact lists Intermediary" posts with a specific custom field value for the "Role" field.
And once you have that specific "Contacts Contact lists Intermediary" posts, you can easily reach to their corresponding "Contact" or "Contact lists" posts, using the "item" attribute:
https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/
First, you'll create a post view set to show "Contacts Contact lists Intermediary" posts, with custom field query filter, to match the role field value with a value passed through a shortcode attribute.
Example screenshot: hidden link
In the "Loop Wizard" in the "Loop Editor" section, select the "List with separators" format to get the minimal output from the view which can be used easily in PHP code later.
Example screenshot: hidden link
On the next screen to select the fields to output, choose only the "Post ID".
The "[wpv-post-id]" shortcode will return the post ID of the current intermediary post, but as we need the ID of the corresponding "Contacts" post, you'll replace both instances of this shortcode with [wpv-post-id item="@contact-contact-list.parent"].
Note: This assumes that the relationship slug is "contact-contact-list" and the "Contacts" post is the parent in the relationship. But please update this to match what is on your website.
Example screenshot: hidden link
After that, you can use view's shortcode like this, with the required custom field value, passed as a shortcode attribute:
[wpv-view name="view-slug" rolevalue="required-role-value"]
Note: You'll replace "view-slug" with the actual slug of this view and "required-role-value" with the actual custom field value, that you need to query for.
Once this view is returning the required post IDs correctly, you can either use "render_view" function ( ref: https://toolset.com/documentation/programmer-reference/views-api/#render_view ) or the "do_shortcode" function ( ref: https://developer.wordpress.org/reference/functions/do_shortcode/ ), to use that output in a custom PHP code.
I hope this helps and please let me know if any step is not clear.
regards,
Waqar