Support

Account

Home Forums ACF PRO ACF – getting fields in functions.php Reply To: ACF – getting fields in functions.php

  • 
    function my_acf_load_value($value, $post_id, $field) {
      // current post id is passed, no need to figure it out
      if (have_rows('artikel', $post_id)) {
        // set up an array to hold values
        // this is becuase a repeater field could have many
        // and will make it easier to concatinate them
        $values = array();
        while (have_rows('artikel', $post_id)) {
          // get value of sub field without formatting
          // so that it will be the ID of the post object
          $post_object_id = get_sub_field('artikel_navn', false);
          // get the field value from the related post object
          // and add to the array
          $values[] = get_field('tekst', $post_object_id);
        } // end while have rows
        // after the loop, implode the values
        $value = implode(', ', $values);
      } // end if have rows
    
      return $value;
    }
    add_filter('acf/update_value/name=meta_beskrivelse', 'my_acf_load_value', 10, 3);