I have a hierarchical custom post type, and on each single view of a post of this type I want to display the full title, content, etc. from the children of this post. This is outside of the main Loop.
However, the code below has very strange results; the post_content and the_ID are from the correct child-post, but the_title and the_permalink are from the parent post, like this:
<h1><a href="parentpermalink.php">Parent Title</a></h1> <p>Parent Content</p> <p>Parent Meta</p> <h1><a href="parentpermalink.php" id="post-first-child">Parent Title</a></h1> <p>First Child Content</p> <h1><a href="parentpermalink.php" id="post-second-child">Parent Title</a></h1> <p>Second Child Content</p>
Using get_children instead of get_posts has the same results:
global $post; $parent = $post->ID; $children = get_posts('post_parent='.$parent.'&&post_type=cruise&&post_status=publish'); foreach($children as $child) : setup_postdata($child); ?> <h2><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"> <?php the_title(); ?></a></h2> <?php the_content(); endforeach; ?>
Any help would be much appreciated.