[wp-trac] [WordPress Trac] #14477: get_pages with child_of only works with uninterrupted hierarchies

WordPress Trac noreply at wordpress.org
Tue Dec 2 16:03:56 UTC 2014


#14477: get_pages with child_of only works with uninterrupted hierarchies
--------------------------------+-----------------------------
 Reporter:  vividvisions        |       Owner:  wonderboymusic
     Type:  enhancement         |      Status:  reopened
 Priority:  high                |   Milestone:  4.1
Component:  Query               |     Version:  3.0
 Severity:  normal              |  Resolution:
 Keywords:  revert 2nd-opinion  |     Focuses:
--------------------------------+-----------------------------
Changes (by boonebgorges):

 * keywords:  has-patch 2nd-opinion => revert 2nd-opinion


Comment:

 Le groan. Thanks for looking into this, dd32.

 The change in order is due to the `$post->ancestors` trick introduced by
 wonderboymusic in [30159]. The problem there is that
 `get_post_ancestors()` returns a flat list. For any item in that list, we
 have no way of knowing where in the tree it lives: whether it's a direct
 parent (post_parent), a grandparent, or further up the tree. When looping
 through the `$pages` passed to `get_page_children()`, then, the `in_array(
 $page_id, $page->ancestors )` is just too coarse.

 I don't think it's possible to salvage this. For 4.1, I recommend
 reverting the changes in `get_pages()` and `get_page_children()` back to
 what they were in 4.0. For 4.2 and beyond, we can look into building a
 properly tree recurser - something like `get_page_children()` (maybe
 `get_page_descendants()`?), but which *would* perform SQL queries to get
 each level of child, so that we'd get an exhaustive and unique descendant
 tree, which would solve the original bug reported in this ticket.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/14477#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list