Display wp_list_pages with dynamicly created exclude list

Adding the first snippet to the functions.php of your wordpress theme will use wp_list_pages but filter out any pages that contain no content creating an excluded_pages array. Then add the second snippet into your wordpress theme in the location you wish to display the pages.




function wps_wp_list_pages(){
$excluded_pages = array();
$all_pages = get_pages();
foreach ( $all_pages as $the_page ) {
if ('' == $the_page->post_content) {
$excluded_pages[] = $the_page->ID;
wp_list_pages( array(
'exclude' => implode(',',$excluded_pages)

<? wps_wp_list_pages(); ?>

Leave a comment