I would try replacing your $children
definition, using get_page_children()
or get_children()
:
<?php
global $post;
$children = get_children( array(
'post_type' => 'page',
'post_parent' => $post->ID,
'post_status' => 'publish'
) );
if ( $children ) {
// Code to list child pages goes here
}
?>
Also, wp_list_pages()
will always return a string (either populated or empty), so if you’re going to test against it, use:
if ( '' != $children )
…instead of just:
if ( $children )
Because the latter will always return true, since the return is an (empty) string.