Opened 2 years ago
Last modified 2 years ago
#15667 new defect (bug)
wp_list_pages, if it finds no pages to display, shows random child pages instead because of a bug in get_pages()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | General | Version: | 3.0.2 |
| Severity: | critical | Keywords: | wp_list_pages needs-patch |
| Cc: |
Description
How to reproduce:
- About page is published
- additionally, there is a number of parent pages
- these each have a number of children
- when calling wp_list_pages(), the "exclude" attr excludes all parent pages, and display only the About page.
This works as long as there is at least 1 other page published that is not in the list of excluded IDs. In this example, as soon as the About page is set to "draft", wp_list_pages stops working correctly.
So... with no other pages besides the excluded ones published, we do this:
1) wp_list_pages('title_li=&depth=1&exclude=3,5,7');
=> wp_list_pages SHOULD return nothing, but instead it displays all child pages of the first parent page ID in the "exclude" attr (here: 3).
Now we now add the "exclude_tree" attr just for fun:
2) wp_list_pages('title_li=&depth=1&exclude=3,5,7&exclude_tree=3,5,7');
=> should again return nothing, but instead, it displays the first-ever published child page globally (here: a child page of 5).
It looked like random behavior at first but I've been able to identify the above pattern. I'm guessing it's a failing condition somewhere in the function.
Change History (1)
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
- Summary changed from wp_list_pages, if it finds no pages to display, shows random child pages instead to wp_list_pages, if it finds no pages to display, shows random child pages instead because of a bug in get_pages()

It looks like the problem is that get_pages() is returning the incorrect pages in all exclude situations, but the page Walker orphans the children (so doesn't display them) in most of those cases. In the ones you list above, though, the Walker does not orphan the children because there's no parent for it to start walking at.
The root of the problem is get_pages(), since the Walker's behavior when fed bad data like this should probably be left undefined.
As a workaround, you can set parent=0.