Wordpress trying to get value of ACF field always returns NULL

Viewed 102

I am trying to loop through a field group in ACF and get the value of certain fields inside that group.

This is working pretty good for the ID and $fields = acf_get_fields(1996) works perfectly aswell but why does it always return NULL for my variable $thename?

I have been wrapping my head around this for like 2 hours now and I just can't figure out why it doesn't access the given field.

Did I forget something or is my logic twisted?

I appreciate any help.

$fields = acf_get_fields(1996);
$thename = get_field('field_5e171593783a1', 1996);
$json = [];

foreach ($fields as $name => $value) {

    array_push($json, 'ID: ' . $value['ID'], $value[$thename]);

}

SOLVED

Found out that I used the wrong Post ID - instead of using the Post ID of the post I was trying to access, I wrongly used the Post ID of the field Group itself, which indeed did not have any values so ended up returning NULL.

0 Answers
Related