I recently had an instance where I had a repeater that had a relationship field to other custom field post types that had a repeater field in the related custom post type.
I used the api tags available which did pull the data, however, it seemed to get into an endless loop and killed Chrome:
Instead I used straight php to get the data to display without server lag. If anyone has a better solution, please let me know and if anyone has a similar issue, I hope this helps:
I used the api tags available which did pull the data, however, it seemed to get into an endless loop and killed Chrome:
<?php if( get_field('repeater_field') ): /* check for rows (sub repeater) */ ?>
<?php while( has_sub_field('repeater_field') ): /* loop through rows (sub repeater) */ ?>
<?php the_sub_field('relationship_repeater_sub_field'); /* display the record value */ ?>
<?php endwhile; ?>
<?php endif; ?>
Instead I used straight php to get the data to display without server lag. If anyone has a better solution, please let me know and if anyone has a similar issue, I hope this helps:
<?php if(get_field('repeater_field')): /* repeater field */ ?>
<?php while(has_sub_field('repeater_field')): /* repeater field */ ?>
<?php $posts = get_sub_field('sub_relationship_field'); /* relationship field in repeater */ ?>
<?php if( $posts ): ?>
<?php foreach( $posts as $post): /* variable must be called $post (IMPORTANT) */ ?>
<?php setup_postdata($post); ?>
<?php $relationship_repeater = get_field('relationship_repeater_sub_field'); /* get relationship record repeater field */ ?>
<?php if( $relationship_repeater ): /* check for records */ ?>
<?php foreach( $relationship_repeater as $repeater_values ): /* loop through the values of the repeater */ ?>
<?php foreach ( $repeater_values as $single_value ): /* loop through nodes of the indexes */ ?>
<?php echo $single_value; /* display the data value */ ?>
<?php endforeach; /* $repeater_values */ ?>
<?php endforeach; /* $relationship_repeater */ ?>
<?php endif; /* $relationship_repeater */ ?>
<?php $relationship_repeater = get_field('relationship_repeater_sub_field'); /* get repeater sub-field in relationship record */ ?>
<?php if( $relationship_repeater ): /* check for records */ ?>
<?php $first_record = reset($relationship_repeater); /* get the first index of the array */ ?>
<?php $second_record_value = array_slice($first_record,1,1,true); /* get the second record only of the variable array */ ?>
<?php foreach( $second_record_value as $data_value ): /* loop through the values */ ?>
<?php echo $data_value; /* display the record value */ ?>
<?php endforeach; /* $second_record_value */ ?>
<?php endif; /* $relationship_repeater */ ?>
<?php endforeach; /* $posts as $post */ ?>
<?php wp_reset_postdata(); /* IMPORTANT - reset the $post object so the rest of the page works correctly */ ?>
<?php endif; /* $posts */ ?>
<?php endwhile; /* has_sub_field('sa_related_experts') */ ?>
<?php endif; /* get_field('sa_related_experts') */ ?>