The third line of your code specifies the page
post type by checking if is_page()
. You can change that to is_singular('your-post-type')
so that it runs, then in your call to wp_list_pages()
you also need to add a post_type
argument so that that part of the code knows what to look for.
So, to have this shortcode work on both Pages and your specific CPT, sub in your post type’s registered name in both places below where uve_courses
appears:
function v_list_child_pages() {
global $post;
// for Pages with a parent
if ( is_page() && $post->post_parent ) {
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=" . $post->post_parent . "&echo=0' );
// for individual CPTs with a parent
} elseif(is_singular('uve_courses') && $post->post_parent ) {
$childpages = wp_list_pages( 'post_type=uve_courses&sort_column=menu_order&title_li=&child_of=" . $post->ID . "&echo=0' );
}
if ( $childpages ) {
$string = '<ul>' . $childpages . '</ul>';
}
return $string;
}
add_shortcode('v_childpages', 'v_list_child_pages');
If you have additional CPTs you want this to work on, you will need to add additional else
clauses to pass those post types.