Support

Account

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