[wp-trac] [WordPress Trac] #52313: BUG: get_pages() and parameters number, child_of

WordPress Trac noreply at wordpress.org
Fri Jan 15 22:43:04 UTC 2021


#52313: BUG: get_pages() and parameters number, child_of
--------------------------+-----------------------------
 Reporter:  Tkama         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.6
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 For Example we have 100 different pages and such pages structure among
 other pages:

 - ID 5
    - ID 20
    - ID 30
        - ID 40

 Now try to get childs of 5 with `number` parameter specified:

 {{{#!php
 <?php
 $pages = get_pages( [
   'child_of' => 7,
   'number'   => 6,
 ] );

 // result: $pages = [];
 }}}

 As one of results (depends on how pages was created) we get empty
 `$pages`.

 But if we delete `number` parameter we get all childrens as expected

 {{{#!php
 <?php
 $pages = get_pages( [
   'child_of' => 7,
 ] );

 /*
 result:
 $pages = Array
 (
     [0] => WP_Post Object
         (
             [ID] => 20

         )

     [1] => WP_Post Object
         (
             [ID] => 30

         )

     [2] => WP_Post Object
         (
             [ID] => 40

         )

 )
 */
 }}}


 This happens because `get_pages()` gets pages only by post_type and LIMIT
 SQL parameters and then try to find childrens of post 5 among retrieved 6
 query results. Of course it can't be done. And and on the other hand, when
 number parameter isn't set there is no LIMIT in sql query, and we get all
 pages of specified type, and after that collect childs of post 5.

 As a minimum solution I think we need to cancels the `number` parameter if
 `child_of` parameter is set.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52313>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list