Support

Account

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!