I have created a group field
album_group that includes groups inside it. What I’m trying to figure out now is how to output the text fields inside
album_information. For example, get the
campaign_title field using the usual
<?php echo get_field('campaign_title');?>
Am I correct in saying I can access the nested group fields without having to use a loop? I’d rather just access them so I can place in certain divs etc.
All good, worked it out by putting it through the loop then accessing the sub_fields!
<?php if( have_rows('album_group') ): while( have_rows('album_group') ): the_row(); $cp_album_info = get_sub_field('album_information'); $cp_album_music = get_sub_field('album_music_g'); $cp_album_name = get_sub_field('campaign_album_name'); $cp_album_links = get_sub_field('album_links'); ... ?>
I had the same problem and it drove me nuts. This should be mentioned in the docs somewhere. I know it is on the groups page of the docs, but it does not state WHY.
Using the variables isn’t working for me, neither is the basic code from the documentation. I also tried the loop have_rows() function but with no success. Can someone help me?
$phone = get_field(‘contact_phone’);
if( $phone ): ?>
<p class=”heading-8″><?php echo $phone[‘title’]; ?></p>
<?php endif; ?>
I’m using this documentation as reference and like I said, neither of those methods are working.
<div class="war-front-form"> <? php if( have_rows('warranty-member') ): //parent group field while( have_rows('warranty-member') ): the_row(); // vars $name = get_sub_field('warranty-name'); $birth = get_sub_field('warranty-birth'); $phone = get_sub_field('warranty-phone'); $email = get_sub_field('warranty-email'); ?> <div class="war-front-member"> <h1>고객정보</h1> <ul> <li><span>이름</span><p><?php echo $name ?></p></li> <li><span>생년월일</span><p><?php echo $birth ?></p></li> <li><span>연락처</span><p><?php echo $phone ?></p></li> <li><span>이메일</span><p><?php echo $email ?></p></li> <li> <?php if( have_rows('warranty-adress-group') ): //child group field while( have_rows('warranty-adress-group') ): the_row(); // vars $postcode = get_sub_field('warranty-postcode'); $adress = get_sub_field('warranty-adress'); $adress2 = get_sub_field('warranty-adress-2'); ?> <span>주소</span> <p><?php echo $postcode ?></p> <p><?php echo $adress ?></p> <p><?php echo $adress2 ?></p> <?php endwhile; ?> <?php endif; ?> </li> </ul> </div> <?php endwhile; ?> <?php endif; ?>
this is my group in group source code
If you don’t need to use loops, this will work for you.
<?php $our_services = get_field('our_services'); // 'our_services' is your parent group $service_one = $our_services['service_one']; // 'service_one' is your child group ?> <?php echo $service_one['service_heading']; // 'service_heading' is a subfield of your child group ?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2019 Advanced Custom Fields. Subscribe