Support

Account

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>