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),
        );
}
  • 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 '16 at 18:39
  • @Howdy_McGee, $label_text give me null value – Adrian Chicu Jul 22 '16 at 18:44
up vote 0 down vote accepted

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;
}
  • This was the problem. Now it works. Thanks. I feel so stupid... :) – Adrian Chicu Jul 22 '16 at 18:54
  • It happens bro :) Welcome. – Aftab Jul 22 '16 at 18:56

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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