Hello,
I'm relatively new to WordPress and not a PHP guru, so I'm certainly missing something obvious, but I can't retrieve child entries on a parent article page. I'm using Types on a testing website running locally (MAMP). I'm using the Bootstrap Toolset theme, and trying to display child posts using the single.php file.
I have a child CTP called "location". Its parent is an article (not a custom post type, if it makes any difference). What I want to achieve: if an article has a child, then show its title at the end of the page.
Following the instructions found in the docs and in other threads in this forum, I wrote the following code to add the child post to my loop:
<?php while ( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); ?> <?php $child_posts = types_child_posts('location'); foreach ($child_posts as $post) { echo $child_post->post_title; } ?> <?php endwhile; ?>
I'm sure that the article I created has a child, I can see it in the admin panel, but nothing is displayed on the article page. 'location' is the slug of my child CPT – checked twice, just to be sure. Anything added inside the loop is displayed correctly, only the child title is missing.
What am I doing wrong? Can you please point me to the right direction?