Opened 15 years ago
Closed 10 years ago
#13412 closed enhancement (fixed)
Parent parameter returns no results in get_pages()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
The get_pages()
function in post.php returns no results when parent != 0, rather than returning the pages that are children of the immediate page.
Given page ID 30, which has 3 child pages, calling get_pages('parent=30')
will return nothing.
The problem is in the following lines (line ~2600 at the time of writing):
if ( $child_of || $hierarchical ) $pages = & get_page_children($child_of, $pages);
Hierarchical, by default, is set to true, this this conditional will typically be true. When it does so, it filters out all of the pages retrieved up to this point and, by the time it returns, there are no pages left.
The quick work-around I'm currently using is to call the following instead:
get_pages('parent=0&hierarchical=0');
overriding the default value so that conditional doesn't execute.
The one exception to this is that calling get_pages('parent=0')
should function even with this bug.
Change History (5)
#2
@
15 years ago
- Milestone changed from Unassigned to Future Release
- Type changed from defect (bug) to enhancement
From Codex: "Also note that the hierarchical parameter must be set to 0 (false) -- which is not default -- or else no results will be returned for any page other than the root (ID=0)."
Noted behavior here:
http://codex.wordpress.org/Function_Reference/get_pages
If corrected, the documentation should be updated.