Support

Account

Home Forums Add-ons Repeater Field Hide the title if the repeater's subfields are empty Reply To: Hide the title if the repeater's subfields are empty

  • Hello, this solved my problem:

     
    <?php
    if( have_rows('repeater_field_name') )
    {
    	$field_key = "repeater_field_number";
    	$field = get_field_object($field_key);
    
    	foreach($field['value'] as $value)
    	{
    	if(!empty($value['repeater_subfield_name']))
    		{
    		$not_empty = true;
    		break;
    		}
    	}
    
    	if($not_empty == true)
    	{
    	echo '<h2>' . $field['label'] . '</h2>';
    	}
    
    	echo '<ul>';
    	while ( have_rows('repeater_field_name') )
    	{		 					
    	the_row();
    	$subfield = get_sub_field('repeater_subfield_name');
    				
    		if( !empty($subfield) )
    		{
    		echo '<li>' . $subfield . '</li>';
    		}
    	}
    	echo '</ul>';
    }
    ?>