Opened 16 years ago
Closed 3 months ago
#10230 closed defect (bug) (worksforme)
get_pages function: number and child_of parameters conflict
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 2.8 |
| Component: | Posts, Post Types | Keywords: | needs-refresh |
| Focuses: | template | Cc: |
Description (last modified by )
Passing both number and child_of parameters to get_pages will produce nonsensical results.
Within the function number is used first to limit the number of results, then child_of is used to establish results within a certain hierarchical scope.
So with a structure of:
Parent 1 Parent 2 Parent 3 Child 1 Child 2 Child 3
passing a number=2 and child_of=(parent 3 id) will not give the expected output. In this case, the result will first be limited to only include:
Parent 1 Parent 2
so the child_of will be ignored. To produce a more logical result, child_of should be evaluated first, then number should be evaluated to limit the result set.
Attachments (1)
Change History (18)
#2
@
16 years ago
- Component changed from General to Query
- Milestone changed from 2.8.1 to 2.9
- Owner set to ryan
#4
@
16 years ago
the proposed patch passes the number argument to the get_children function and prevents get_pages from limit(ing) the result from the query.
works fine on one of my client's site.
#7
@
16 years ago
A quick fix for this is to pass in the "parent={parent_id}" along with all your other arguments. Obviously not a fix for the bug but if you need this sort of functionality then it will work for now.
#8
@
16 years ago
- Keywords needs-testing added; get_pages wp_list_pages removed
- Milestone changed from 3.0 to Future Release
Bumping to Future release due to limited traction.
This also needs testing to ensure it doesn't break on complex queries involving children and offset/number
This ticket was mentioned in Slack in #core-test by sirlouen. View the logs.
3 months ago
#17
@
3 months ago
- Keywords has-patch needs-testing removed
- Resolution set to worksforme
- Status changed from assigned to closed
Reproduction Report
Description
❌ This report can't validates that the issue can be reproduced anymore
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.29
- Server: nginx/1.29.1
- Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
- Browser: Chrome 139.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Three 1.6
- MU Plugins: None activated
- Plugins:
- BBB Testing Dolly
- Test Reports 1.2.0
Testing Instrutions
- Added the structure of Parent/Childs as in OP
- Used the snippet provided in Supp Artifacts
- 👌 Two Childs are shown as expected
Actual Results
- ❌ Error condition is not occurring
Additional Notes
- Things have changed significantly for the past years and the function does not look not even close to what it used to look when patch was released. For this reason I have to close this as
worksforme
Supplemental Artifacts
function test_get_pages() {
$parent3_id = 161;
$pages = get_pages(array(
'number' => 2,
'child_of' => $parent3_id,
));
echo '<pre>';
if (!empty($pages)) {
foreach ($pages as $page) {
echo 'Title: ' . $page->post_title . "\n";
}
} else {
echo 'No pages found.';
}
echo '</pre>';
}
add_action('wp_footer', 'test_get_pages');

I meant to demonstrate the heirarchy as the following:
Parent 1
Parent 2
Parent 3