Make WordPress Core

Opened 16 years ago

Closed 3 months ago

#10230 closed defect (bug) (worksforme)

get_pages function: number and child_of parameters conflict

Reported by: ortsaipekim's profile ortsaipekim Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Posts, Post Types Keywords: needs-refresh
Focuses: template Cc:

Description (last modified by SergeyBiryukov)

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)

patch.post.php (1.4 KB) - added by arakeis 16 years ago.

Download all attachments as: .zip

Change History (18)

#1 @ortsaipekim
16 years ago

I meant to demonstrate the heirarchy as the following:

Parent 1
Parent 2
Parent 3

Child 1
Child 2
Child 3

#2 @Denis-de-Bernardy
16 years ago

  • Component changed from General to Query
  • Milestone changed from 2.8.1 to 2.9
  • Owner set to ryan

@arakeis
16 years ago

#3 @arakeis
16 years ago

  • Keywords has-patch added

#4 @arakeis
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.

#5 @arakeis
16 years ago

  • Cc arakeis added

#6 @ryan
16 years ago

  • Milestone changed from 2.9 to 3.0

#7 @JoshSalverda
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 @dd32
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

#9 @SergeyBiryukov
13 years ago

  • Component changed from Query to Template

Closed #10745 as a duplicate.

#10 @SergeyBiryukov
13 years ago

  • Description modified (diff)

#11 @nacin
12 years ago

  • Component changed from Template to Posts, Post Types
  • Focuses template added

#12 @ryan
11 years ago

  • Owner ryan deleted
  • Status changed from new to assigned

#13 @wonderboymusic
10 years ago

  • Keywords needs-refresh added

#14 @SergeyBiryukov
5 years ago

#52313 was marked as a duplicate.

This ticket was mentioned in Slack in #core-test by sirlouen. View the logs.


3 months ago

#17 @SirLouen
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

  1. Added the structure of Parent/Childs as in OP
  2. Used the snippet provided in Supp Artifacts
  3. 👌 Two Childs are shown as expected

https://i.imgur.com/w4RkYXf.png

Actual Results

  1. ❌ 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');
Note: See TracTickets for help on using tickets.