[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

// returns nothing

// returns pages 4 and 14:

// returns only page 4

// returns nothing

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- 

At any rate, this behavior should be documented.


More information about the wp-hackers mailing list