[wp-trac] [WordPress Trac] #18701: "hierarchical" argument for get_pages() does nothing

WordPress Trac noreply at wordpress.org
Mon Sep 28 17:47:45 UTC 2015


#18701: "hierarchical" argument for get_pages() does nothing
-------------------------------+------------------------------
 Reporter:  Viper007Bond       |       Owner:  DrewAPicture
     Type:  defect (bug)       |      Status:  accepted
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  3.0
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:
-------------------------------+------------------------------

Comment (by DrewAPicture):

 Took a look at this the other night.

 The truly ''special'' part about the current state of `get_pages()` is
 that because `$hierarchical` is `true` and `$child_of` is `0|false` by
 default, we actually end up with non-hierarchical results ''by default''
 because `$child_of` translates to `parent = 0` in `get_page_children()`.
 To maintain backward-compatibility, we would have to retain that default
 behavior

 Running two rudimentary tests of current behavior, I got surprising
 results:

 {{{
 $hierarchical = get_pages( array( 'number' => 10 ) );
 $hierarchical = wp_list_pluck( $hierarchical, 'post_parent' );
 // 5 pages, all with parent 0

 $non_hierarchical = get_pages( array( 'hierarchical' => false, 'number' =>
 10 ) );
 $non_hierarchical = wp_list_pluck( $non_hierarchical, 'post_parent' );
 // 10 pages, mixed parents
 }}}

 If we wanted to truly implement hierarchical results, there are a couple
 of things to consider:
 * Like `get_terms()`, we should probably only set the `LIMIT` clause if
 `$hierarchical`, `$child_of` and `$parent` are falsey and `$number` is not
 empty. Currently it's always set if `$number` is not empty (default is
 empty)
 * It should be documented what exactly "hierarchical" means in terms of
 returned results

 I think the best starting place is to write tests for the current behavior
 and work outward.

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


More information about the wp-trac mailing list