Home Forums General Issues Can related posts inherit ACF field values?


Can related posts inherit ACF field values?

  • I am newer to ACF but can’t seem to find out if this is possible. Is it possible for related posts to inherit specific ACF field values?

    For example, I am trying to create a card game database where the base card has multiple variants. So one Base Card 1 will have Variant 1, 2, 3, etc. So I have a Field Group for Base Cards that includes things like Power and Cost. Is it possible for the values in the Base Card for Power and Cost to be inherited in Variant 1, 2, and 3? So for example, if I put Power 1 in Base Card 1, then Variants 1, 2, and 3 would all inherit that value of 1 in their Power field? Then, if I update the Power value to 2, each of the Variants will update.

    I’ve seen answers about global fields in the ACF Pro Options settings, but I’m going to have 300+ Base Cards, so I’m not sure that I want to create that many global variables. I know I could bulk edit too, but I’m trying to figure out a way to link fields between posts so the values sync. I already have a relationship between the Base Card and each Variant.

    I have searched documentation, videos, and this forum, but haven’t found what I am looking for. Maybe I’m using the wrong search terms. Thanks for any assistance you can give me!

  • 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!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.