Opened 4 years ago
Closed 4 years ago
#52313 closed defect (bug) (duplicate)
BUG: get_pages() and parameters number, child_of
Reported by: | Tkama | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.6 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
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 $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 $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.
Hi there, welcome back to WordPress Trac!
Thanks for the report, we're already tracking this issue in #10230.