Home › Forums › Add-ons › Repeater Field › Repeater Relationship Post Fields from Array › Reply To: Repeater Relationship Post Fields from Array
Hi @rktlwm
Thanks for the follow up and the attachments. I can now see how you need to work with the data.
What you need to do is loop over the repeater field and look at the selected case. Load the case’s type (internal / external) and then append this data to an array.
After the repeater field loop is complete, you should have an array containing all the external and all the internal cases. You can then loop through these and output the 2 lists like so:
<?php
$internal = array();
$external = array();
if ( get_field('test_cases') ): ?>
<?php while(has_sub_field('test_cases')):
// get case
$case = get_sub_field('case_relationship');
$case = array_pop($case);
// get case data
$data = array(
'type' => get_field('type', $case),
'description' => get_sub_field('case_custom_desc'),
'title' => get_the_title($case),
'link' => get_permalink($case)
);
$type = get_field('type', $case);
$description = get_sub_field('case_custom_desc');
$title = get_the_title($case);
$link = get_permalink($case);
if( $type == 'internal' )
{
$internal[] = $data;
}
else
{
$external[] = $data;
}
?>
<?php endwhile; ?>
<?php endif; ?>
Please note the above code is untested. So with this code, you will have all the case data in 2 arrays (internal and external) which you can loop over and output into the 2 columns for each post.
Good luck
Thanks
E
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.