Hi,
it would be great to set dynamically a custom field based on the value of a custom field of another CPT. Is it possible somehow?
To be clear, I have a CPT ‘Dishes’ that contains dishes served in Restaurants.
Restaurants is also a CPT, it contains many restaurants. I link the two through a Post Object Custom Field (in Dishes, I set the Restaurant where the dish is served).
Then, I set the address of the Restaurant in a custom field of the Restaurants CPT.
Is it possible to retrieve the address from that Restaurants’ custom field and set it as value for a custom field in Dishes CPT?
That’s because I would like to show the address also in the Dishes (and not only in the Restaurant).
Hope to have been clear.
Thanks in advance,
Daniele
When you are showing the “Dish” and listing the “Restaurant” you can get and show the address from the restaurant, you just need to supply the restaurant post ID when you call get the field.
// assumes that the post object field on "Dish" returns "Post Object"
$restaurant = get_field('restaurant');
$address = get_field('address', => $restaurant->ID);
https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/