Home › Forums › Add-ons › Repeater Field › Object field inside a repeater not working right. › Reply To: Object field inside a repeater not working right.
Hi fgenois,
It seams you have the same issue as explain here. As I told to Dada, you probabely kill the query loop by using setup_postdata(), plus, when you want to get_field in a loop which is in a loop (and again and again) it’s better to call the field with the post ID.
Try this (same logic as the Dada issue, not functional, only to show the logical path) :
$args = array(...);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post() ;
$query_post_id= get_the_ID();
if( have_rows('repeater_you_wan', $query_post_id)) {
while ( have_rows('repeater_you_wan', $query_post_id)) : the_row(); // get row with the query_id to avoid mistake
[...] // Write your html
$posts_from_repeater = get_sub_field('your_multiple_post_object_subfield');
if($posts_from_repeater) {
foreach ($posts_from_repeater as $sub_post) { // Where $sub_post is post object
$sub_post_id = $sub_post->ID;
$my_post_field_data = get_field('my_post_field_data', $sub_post_id);// get field with the query_id to avoid mistake
$my_post_title = get_the_title($sub_post); // can get title by post object
[...] // Write your html
[...] // Write your html
[...] // Write your html
}
}
[...] // Write your html
endwhile;
}
}
}
wp_reset_postdata();
PS : when you write code, use the code balise it’s will be easier to read.
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.