How to Fix the “Exclude Pages from List” WordPress Bug

This is another annoying WordPress bug I discovered about 4 months ago. I posted this bug on the WordPress support forum but the WordPress team have not fixed it yet. This “exclude pages from list” bug only affects you if you use WordPress pages with sub pages. WordPress 2.5 and up do not seem to allow the hiding of certain sub pages with the “exclude” parameter. The exclude parameter is supposed to do the following as documented by WordPress:

Exclude Pages from List

Use the exclude parameter hide certain Pages from the list to be generated by wp_list_pages. Excluding a Page will also exclude all of its sub-pages from the list to be generated.

The last time this worked was in WordPress 2.3.3. Sadly, it is still not working in WordPress 2.6.1.

To fix this bug, you will need to replace the wp_list_pages function with the one in WordPress 2.3.3. Open the file “post-template.php” in the “wp-includes” folder with your favourite text/html editor.

Copy the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function wp_list_pages($args = '') {
$defaults = array(
'depth' => 0, 'show_date' => '',
'date_format' => get_option('date_format'),
'child_of' => 0, 'exclude' => '',
'title_li' => __('Pages'), 'echo' => 1,
'authors' => '', 'sort_column' => 'menu_order, post_title'
);
 
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
 
$output = '';
$current_page = 0;
 
// sanitize, mostly to keep spaces out
$r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);
 
// Allow plugins to filter an array of excluded pages
$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
 
// Query pages.
$pages = get_pages($r);
 
if ( !empty($pages) ) {
if ( $r['title_li'] )
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
 
global $wp_query;
if ( is_page() )
$current_page = $wp_query->get_queried_object_id();
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
 
if ( $r['title_li'] )
$output .= '</ul></li>';
}
 
$output = apply_filters('wp_list_pages', $output);
 
if ( $r['echo'] )
echo $output;
else
return $output;
}

Replace the entire area of the code of the existing wp_list_pages function, which looks something like “wp_list_pages($args = ”) { blah blah blah }“. Once you have done this, your WordPress pages will display sub pages and exclude certain pages correctly.

About the Author

Similar Posts

Facebook Comments

-->

1 Comment On “How to Fix the “Exclude Pages from List” WordPress Bug”

On 1st October 2008 2:54 PM, fedmich said:

or you can simply do this patch,
http://www.texto.de/texto/wp-25-wp_list_pages-exclude-bugfix/#comment-21715

2 Trackbacks On “How to Fix the “Exclude Pages from List” WordPress Bug”

Post a Comment


(Required)


(Required)