Home › Forums › General Issues › Can related posts inherit ACF field values? › Reply To: Can related posts inherit ACF field values?
If you have the posts linked already I think you’d just need to update the field in the relationship posts when the post is saved.
I used update_field() and ACF/save_post
I’ve done something similar in a solution I built to update the field values of a specific post from any page on the website.
function update_variant_fields($post_id) {
// Get related Base Cards using the relationship field
$base_cards = get_field('base_card_relationship_field', $post_id);
if ($base_cards) {
foreach ($base_cards as $base_card_post) {
$power = get_field('power', $post_id);
$cost = get_field('cost', $post_id);
update_field('power', $power, $base_card_post->ID);
update_field('cost', $cost, $base_card_post->ID);
}
}
}
add_action('acf/save_post', 'update_variant_fields'); // Update on post save
I realized after I made it could have probably changed $base_card_post->ID into its own variable.
Hope this helps!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.