Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type with two levels of pages inside of it. the parent level we'll call parent, and child - child.

The parents need to be able to pull in their children, and the children need to be able to pull in their siblings (children of the same parent.)

If i were doing this in a normal page:

<?php $children = get_pages('child_of='.$post->ID);?>
if( count( $children ) != 0 ) { ?>
<section class="children">
Give us your Children
</section>
<?php }
else { ?>
<section class="siblings">
Give us your siblings
</section>
<?php } ?>

Of course - this doesn't work since get_pages only works with non-cpt "pages". I'm at a loss for the proper method inside a CPT - help much appreciated.

share|improve this question

1 Answer 1

get_pages() works with other post types just fine, you only need to pass post_type you want as part of argument (also I recommend to stick with array notation).

$children = get_pages( array( 'child_of' => $post->ID, 'post_type' => 'your_post_type', ) );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.