Home › Forums › General Issues › Can related posts inherit ACF field values? › Reply To: Can related posts inherit ACF field values?
Thank you, Andrew!
Sorry for the much delayed response. I just got around to looking at this website again and your suggestion helped me figure out what to do and I just got it working this morning. Here is what I ended up using:
function update_variant_fields($post_id) {
// Get related Variant Cards using the relationship field
$variant_cards = get_field('variants', $post_id);
if ($variant_cards) {
foreach ($variant_cards as $variant_card_post) {
$base_power = get_field('power', $post_id);
$base_cost = get_field('cost', $post_id);
update_field('power', $base_power, $variant_card_post->ID);
update_field('cost', $base_cost, $variant_card_post->ID);
}
}
}
add_action('acf/save_post', 'update_variant_fields'); // Update on post save
Thanks so much for the direction!
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.