• Resolved TrishaM

    (@trisham)


    I need to create a list of *sibling only* pages for some sub-pages, and have tried a number of methods (using wp_list_pages), but none are working.

    I can quickly and accurately retrieve and display the Parent Page ID using echo $post-post_parent.

    However when I try to get the child pages of that parent page (the current page’s siblings) like this:

    $siblings = wp_list_pages(array(
         'child_of' => $post->post_parent,
         'echo' => 0
         )
    );
      if ($siblings) {
        echo $siblings;
      }

    I get nothing. I do have sibling pages, just can’t get them to be listed.

    I’ve tried this, even simpler:
    wp_list_pages("title_li=&child_of=".$post->post_parent."");

    Still not working.

    I haven’t had any trouble in creating loops showing all child pages of parent pages elsewhere, it’s just this sibling pages list I’m struggling with.

    Any ideas? I’m on WP 4.3.1

Viewing 1 replies (of 1 total)
  • Thread Starter TrishaM

    (@trisham)

    OK I managed to resolve this, posting here in case anyone else needs this solution.

    Turns out that I needed to add “post_type” to my arguments since this is for a Custom Post Type, and if unspecified the default post type is ‘page’ (since only hierarchical post types have ‘parent’ pages)…WP does not make any assumptions of the post type based on the post parent, so for custom post types you need to specify it.

    SO I modified my code above to:
    wp_list_pages("title_li=&post_type=mycustomtype&child_of=".$post->post_parent."");

    Now it works perfectly and I just need to style my resulting list.

Viewing 1 replies (of 1 total)
  • The topic ‘List sibling pages not working’ is closed to new replies.