Hi,
I do have a custom post type where each post has a relationship field. In that field you can select a user profile. On each user profile page I do have several custom fields. For example radio buttons (red, blue, green)
Post A <–> User A (radio buttons)
Post B <–> User B (radio buttons)
…
Now I want to query posts depending on the settings made on the related user profile page. For example: Query all posts where the related user has chosen “blue”.
Is this somehow possible?
At the moment I am the following code to get the related user profile fields:
$linked_profile = get_field('linked_profile');
$user_ID = $linked_profile['ID'];
$color = get_field('select-color', 'user_'. $user_ID);
Thank you very much for your help!
There is not mechanism in WP that will allow you to query posts based on the meta values of a related post. To query posts all values must be associated with the posts you want to query.
This means that you need to
– create an acf/save_post hook that
– gets the relationship field
– gets the values for the fields on the related post
– saves those values to the post currently being saved