[wp-hackers] get_pages() include vs. hierarchical
Joe Maller
joe at joemaller.com
Sat Oct 13 16:56:50 GMT 2007
I noticed something with get_pages() that some people might consider
a bug.
When using only an include argument, the function won't return
anything if the requested page is nested. This is because the
function defaults to hierarchical display and won't return a child
page unless that page's parent is also included.
The code snippets below are based on the following page structure:
ID 4 (top level page)
-- ID 14 (child page of ID 4)
ID 5 (another top level page)
-- ID 15 (child page of ID 5)
// returns page 4
get_pages('include=4');
// returns nothing
get_pages('include=14');
// returns pages 4 and 14:
get_pages('include=4,14');
// returns only page 4
get_pages('include=4,15');
// returns nothing
get_pages('include=14,15');
In all cases, appending the 'hierarchical=0' argument returns all
requested pages.
In my opinion, the expected behavior of a specifically requested set
of pages should be to return all those pages if they exist. The
get_pages() function already resets several other arguments if it
gets an include list, should the default get_pages() behavior be
modified to also set $hierarchical=0 when the include argument is non-
empty?
At any rate, this behavior should be documented.
joe
More information about the wp-hackers
mailing list