[wp-trac] [WordPress Trac] #17374: get_pages() with child_of forgets sort
WordPress Trac
noreply at wordpress.org
Fri Feb 21 22:25:11 UTC 2014
#17374: get_pages() with child_of forgets sort
------------------------------------+-----------------------------
Reporter: janfabry | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: Posts, Post Types | Version: 3.1.2
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses:
------------------------------------+-----------------------------
Changes (by jessepollak):
* keywords: needs-patch needs-unit-tests => has-patch dev-feedback
Comment:
OK, so it turned out that neither of my ideas were good ones. Both
involved reimplementing parts of the MySQL search, which seemed like Bad
Idea.
Instead, I decided that I'd rewrite the {{{get_page_children}}}. In the
current version, we do a top down recursive search to find all the
children of {{{child_of}}}. The problem with this is that we get all the
children at the same time, so they all get added to the new list at the
same time — this messes up the sort that we had previously.
In this patch, I reverse this so we do a bottom up search with a while
loop to check whether a page has an ancestor with the ID {{{child_of}}}.
If it does, we add it to the new list of pages to return. This maintains
the sorted order because we're iterating through in sorted order and
adding one page at a time. To make this search faster, we add all the
pages to a dictionary so we can do O(1) lookup when traversing up the
tree.
I've also written a unit test that verifies the failed functionality and
confirms the patch. I can write more, if we want.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/17374#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list