I’m displaying a simple sitemap with wp_list_pages();
$args = array(
'sort_column' => 'menu_order',
'title_li' => '',
'post_status' => 'publish'
);
wp_list_pages( $args );
The problem is that by default this also shows the published children of draft pages, like so :
Page 1 (published) -> displayed
— Page 2 (draft) -> not displayed
—— Page 3 (published) -> displayed
What I would like to achieve is :
Page 1 (published) -> displayed
— Page 2 (draft) -> not displayed
—— Page 3 (published) -> not displayed
I suspect a custom Walker would do the trick, but I could never really understand how those work..
Is there a way to hide those child pages without having to set them all to draft ?
Edit:
To clarify, let’s try some imagery. So you have a tree with the complete hierarchy of your pages. We are climbing up the tree. The moment we encounter a a draft branch, we cut it down. Naturally all the other branches attached to it further along are also discarded (no matter if they are drafts or not). I hope that explains it better.
Here is an example with a somewhat deep hierarchy :
Page 1 (published) -> displayed
— Page 2 (draft) -> not displayed <- Cut here and exclude all further children
—— Page 3 (published) -> not displayed
——— Page 4 (published) -> not displayed
———— Page 5 (draft) -> not displayed
————— Page 6 (published) -> not displayed