Home › Forums › ACF PRO › Get siblings via parent relationship. › Reply To: Get siblings via parent relationship.
I’ve got it!
Instead of running another full query – I just ran a local foreach.
<ul class="package">
<?php
$args = array(
'post_type' => 'page',
'meta_query' => array(array(
'key' => 'package-creator',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
));
$getmysiblings = new WP_Query($args) ?>
<?php if ($getmysiblings->have_posts()): ?>
<?php while ($getmysiblings-> have_posts()): $getmysiblings->the_post(); ?>
<?php // get the relationship field ?>
<?php
$siblings = get_field('package-creator');
foreach($siblings as $sibling) {
$sibling_name = $sibling->post_title; ?>
<li><a href="<?php echo post_permalink($sibling); ?>"><?php echo $sibling_name; ?></a></li>
<?php } ?>
<?php // end get relationship field ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<?php endif; ?>
</ul>
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.