[wp-trac] [WordPress Trac] #17374: get_pages() with child_of forgets sort
WordPress Trac
noreply at wordpress.org
Fri Feb 21 16:40:14 UTC 2014
#17374: get_pages() with child_of forgets sort
-------------------------------+------------------------------
Reporter: janfabry | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 3.1.2
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
-------------------------------+------------------------------
Changes (by jessepollak):
* keywords: => needs-patch
Comment:
Thanks for the bug report janfabry, sorry you never got a response!
I just confirmed that this bug is still around in trunk at revision 27076.
To recreate:
1. Create a new page Page 1.
2. Give Page 1 two subpages Page 1a and Page 1b where Page 1b is created
after Page 1a.
3. Give Page 1a a sub page Page 1aa.
4. Run
{{{
$pages = get_pages(array('child_of' => PAGE_1_ID,
'sort_column' => 'post_date',
'sort_order' => 'DESC'
));
}}}
'''Expected:'''
Get Page 1a, Page 1b, Page 1aa in that order (because that's the order
they were created in).
'''Actual'''
The sub pages are ordered Page 1a, Page 1aa, Page 1b.
'''Why'''
This happens because, as janfabry points out, the sort happens when the
all of the pages are gotten. To get the children, we go through all the
sorted pages and select the children and array_merge them into the page
list. If a sub-page has a sub-page, this gets added right behind the sub-
page, potentially messing up the ordering.
There are two possible ways to patch this:
1. When we add each child, we add it in the correct place (more
performant, a little trickier).
2. After we add all the children we sort the list again (less performant,
more tricky).
I'd be happy to write up a patch with either of these options.
Thanks again!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/17374#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list