0

I have a problem with the repeater field in Acf Pro. I want to retrieve fields inside the foreach but it gives me "null" value.

Can someone help me?

My code:

function label_text( $post_id = '' ) {
            while( have_rows('description', $post_id) ): the_row();
                    $description .= get_sub_field('label') . get_sub_field('text');
            endwhile;
    return $description;
}
foreach ( $query->posts as $id ) {
            $label_text = label_text( $id );
            $logo = get_field('logo', $id);
            $results[ get_the_title( $id ) ] = array(
                'id'           => $id,
                'description'  => $label_text,
                'logo'         => $logo['url'],
                'type'         => get_post_type($id),
        );
}
2
  • 3rd Party Plugins ( such as Advanced Custom Fields ) are considered to be Off-Topic here - you may get a faster response from their support team. That being said, what is giving you the null value? $logo? $results?
    – Howdy_McGee
    Jul 22, 2016 at 18:39
  • @Howdy_McGee, $label_text give me null value Jul 22, 2016 at 18:44

1 Answer 1

0

I found a Notice error in your code. You have used $description in your code. Initially you have not defined it and directly using concatenation to it.

function label_text( $post_id = '' ) {
    $description = '';        
    while( have_rows('description', $post_id) ): the_row();
                    $description .= get_sub_field('label') . get_sub_field('text');
            endwhile;
    return $description;
}
2
  • This was the problem. Now it works. Thanks. I feel so stupid... :) Jul 22, 2016 at 18:54
  • It happens bro :) Welcome.
    – Aftab
    Jul 22, 2016 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.