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);
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.