I am attempting to display the child pages of a custom post_type
page. I found a shortcode that works great for standard WordPress "pages" post_type
, but doesn't work on custom post types.
Here is the shortcode code I placed in my overrides functions file:
add_shortcode( 'my_childpages', 'my_list_child_pages' );
function my_list_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
if ( $childpages ) {
$string = '<ul>' . $childpages . '</ul>';
}
return $string;
}
If I place the [my_childpages]
shortcode on a "page" post_type
with children it successfully displays in linked list all sub-pages. But if I add to a custom post_type
(e.g., 'essays'), it doesn't.
I saw elsewhere that perhaps the code doesn't acknowledge the custom $post_type
, and requires an added argument, but I'm not sure how to edit the above code to satisfy. I've tried several edits, but fail.
Any advice or suggestions would be greatly appreciated!