Support

Account

Home Forums Front-end Issues Field Groups

Solved

Field Groups

  • Be nice, please people: I am not a programmer so need very, very precise code.
    I have created six Field Groups and in each group, there are several fields. From the How-to pages, I used this code

    <?php 
     
    $fields = get_field_objects();
     
    <?php if( $fields ): ?>
    	<ul>
    	<?php foreach( $fields as $field ): ?>
     
    		<?php if( $field['value'] ): ?>
    			<li><?php echo $field['label']; ?>: <?php echo $field['value']; ?></li>
    		<?php endif; ?>
     
    	<?php endforeach; ?>
    	</ul>
    <?php endif; ?>

    which works perfectly.
    How do I get the fields groups to display with their unique fields eg
    Field Group 1
    field 1
    field 2
    Field Group 2
    field 1
    field 2

    and so on…

  • Hi @stingo

    Currently, there is no way to separate the fields into field groups with labels.
    This will be possible in the soon to be released version5, but for now. You will need to hardcode the heading for each field group.

    An easy way to do this is to create an array which contains all the field names for the field group, then loop through that and display the field like so:

    
    <h2>Field Group Name</h2>
    <?php 
    
    $fields = array(
    	'field_name_1',
    	'field_name_2',
    	'field_name_3'
    );
    
    ?>
     
    <?php if( $fields ): ?>
    	<ul>
    	<?php foreach( $fields as $field ): 
    		
    		$field = get_field_object( $field );
    		
    		?>
     
    		<?php if( $field['value'] ): ?>
    			<li><?php echo $field['label']; ?>: <?php echo $field['value']; ?></li>
    		<?php endif; ?>
     
    	<?php endforeach; ?>
    	</ul>
    <?php endif; ?>
    

    Hope that helps

    Thanks
    E

  • .. and looking forward to ver 5 being released.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Field Groups’ is closed to new replies.