Support

Account

Home Forums Front-end Issues Field Groups

Solved

Field Groups

    • Stingo

    • December 17, 2013 at 1:48 pm

    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…

    • Elliot

    • December 18, 2013 at 9:57 am

    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

    • Stingo

    • December 22, 2013 at 1:28 am

    Thank you.

    • Stingo

    • December 22, 2013 at 1:28 am

    .. and looking forward to ver 5 being released.

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

You must be logged in to reply to this topic.

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.