2

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.

1 Answer 1

3

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', ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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