Home › Forums › Front-end Issues › Displaying Sibling ACF Fields › Reply To: Displaying Sibling ACF Fields
After doing some more reading I found that I can pass a pageID to have_rows
and retrieve fields that way, so I thought I could maybe retrieve an array of all the siblings of a page and just loop through them. However, I can’t find the appropriate way to do this. Am I going about this right way? Is there a better way to implement to this?
<?php
$pageId = array-of-sibling-ids.
?>
<?php
foreach ($pageId as $sibling) {
if( have_rows('single_project_hero', $sibling) ):
while( have_rows('single_project_hero', $sibling) ): the_row();
$image = get_sub_field('single_project_hero_image');
$heading = get_sub_field('single_project_hero_headline');
$teaser = get_sub_field('single_project_hero_teaser');
?>
<?php if ($image): ?>
<div class="singleProject__hero">
<img src="<?php echo $image ?>"/>
<div class="singleProject__heroCopy centered-heading">
<h2 class="title"><?php echo $heading ?></h2>
<p class="copy"><?php echo $teaser ?></p>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.