Use https://developer.wordpress.org/reference/functions/wp_list_pages/
set the post_type to your CPT and child_of to the current page
Thanks.
Struggling to understand this after too many hours staring at a screen, how do I ‘set child_of to the current page’?
I assume it begins with ‘ ‘child_of’ =>’ but I can’t even guess the rest.
there are two possible ways:
$post_id = get_the_ID();
and
global $post;
$post_id = $post->ID;
Here’s some code for a filter I created that automatically adds the children of a page called “services” after the page’s usual content
/* for the services page, list children */
function pcs2n_list_children( $content ) {
global $post;
if ( is_page( 'services' ) ) {
$args = array(
'child_of' => $post->ID,
'title_li' => '',
'echo' => false,
);
$content .= wp_list_pages( $args );
}
return $content;
}
add_filter( 'the_content', 'pcs2n_list_children' );
Thanks.
I understand the ‘list children” snippet – and can adapt that to use on various pages.
But I couldn’t adapt it to use on a cpt.
I’m clearly failing to understand something which is probably quite straightforward… using my existing knowledge I can produce a page which lists all members of a cpt, but on a page for one member of that cpt I can’t show a list of children of that member.
In the above, you’d add ‘post_type’=> get_post_type() and it should list children for that particular post.
Steve thanks…
Sometimes when looking at forum posts and seeing someone come back for clarification, I think ‘Jeez, you have all the clues there – it’s not that difficult.’
Finding myself (again) in such a position, I think I should return to this later with a clear head… so then, let’s relax with ‘Box of Rain’ and think about anything other than WordPress. Maybe I’m just not suited to this. 😉
Maybe you’ll find direction
around some corner
where it’s been waiting to meet you
😉
Hopefully, yeah.
‘I will get by… La dee da da da, La da da da da’.
Waaaaaaay off topic, I should stop this nonsense.