Support

Account

Forum Replies Created

  • i was able to figure it out by using get_posts.

    
      $siblingProjects = get_posts(array('post__not_in' => array($pageId), 'showposts' => 20, 'post_parent' => $parentId, 'post_type' => 'page'));
    
  • Hey John,

    Thanks for replying. To clarify my question, I’m currently displaying one of the child pages, and on that page I’m trying to query for the ids of all the sibling pages. I tried the following:

    
    <?php
      $pageId = $wp_query->post->ID;
      $parentId = wp_get_post_parent_id( $pageId );
      $query = new WP_Query( array( 'post_parent' => $parentId ) );
    ?>
    

    However, in the $query object I don’t see any of the siblings nor their ids. Am I missing something?

  • 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; ?>
    
Viewing 3 posts - 1 through 3 (of 3 total)