Support

Account

Home Forums ACF PRO Get next field value in foreach loop through field group Reply To: Get next field value in foreach loop through field group

  • Just to clarify, this works:

    
    $show_hide_pricing_structure = get_field_object('show_hide_pricing_structure');
    $pricing_structure = get_field_object('pricing_structure');
    $show_hide_base_rent = get_field_object('show_hide_base_rent');
    $base_rent = get_field_object('base_rent');
    $show_hide_pricing_metric = get_field_object('show_hide_pricing_metric');
    $pricing_metric = get_field_object('pricing_metric');
    $show_hide_lease_type = get_field_object('show_hide_lease_type');
    $lease_type = get_field_object('lease_type');
    
    if($show_hide_pricing_structure['value'] == '1') {
    	echo '<tr>';
    	echo '<td class="detail-key">' . $pricing_structure['label'] . '</td>';
    	echo '<td class="detail-value">' . $pricing_structure['value'] . '</td>';
    	echo '</tr>';
    }
    
    if($show_hide_base_rent['value'] == '1') {
    	echo '<tr>';
    	echo '<td class="detail-key">' . $base_rent['label'] . '</td>';
    	echo '<td class="detail-value">$' . $base_rent['value'] . '</td>';
    	echo '</tr>';
    }
    
    if($show_hide_pricing_metric['value'] == '1') {
    	echo '<tr>';
    	echo '<td class="detail-key">' . $pricing_metric['label'] . '</td>';
    	echo '<td class="detail-value">' . $pricing_metric['value'] . '</td>';
    	echo '</tr>';
    }
    

    However this is not really easy to maintain and if the fields change or some are added, it doesn’t do the job.

    Looping through the fields seems like the right way to do this however I need to be able to access the next value in the array for it to work.