0

I have a custom post type called donation_group it has a custom_field called donate_pages which is a repeater field. This donate_pages has again fields called donation_object and amount_received. I want to access these custom fields in my controller ie php file.

This is the code I have tried so far

 $donation_group_posts = Timber::get_posts(array(
        'post_type' => 'donation_group'
    ));

    foreach ( $donation_group_posts as $dg_post ) {
        $dg_donate_pages = $dg_post -> donate_pages;
        echo "dg_donate_pages", $dg_donate_pages;
    }

When I echo dg_donate_pages, I am only getting the number of rows that repeater field has. How can I get its values?

1 Answer 1

0

Try this:

foreach ( $donation_group_posts as $dg_post ) {
    $dg_id = $dg_post->ID;

    if(have_rows('YOUR_REPEATER_SLUG', $dg_id)){
        while(have_rows('YOUR_REPEATER_SLUG', $dg_id)) : the_row();
            echo get_sub_field('YOUR_FIELD_SLUG');
        endwhile;
    }

}
1
  • Thank you so much @samuel it worked.
    – Praneetha
    Dec 26, 2019 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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