Make WordPress Core

Opened 17 years ago

Closed 11 months ago

#10230 closed defect (bug) (worksforme)

get_pages function: number and child_of parameters conflict

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

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 17 years ago.

Download all attachments as: .zip

Change History (18)

#1 @ortsaipekim
17 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
17 years ago

  • Component GeneralQuery
  • Milestone 2.8.12.9
  • Owner set to ryan

@arakeis
17 years ago

#3 @arakeis
17 years ago

  • Keywords has-patch added

#4 @arakeis
17 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
17 years ago

  • Cc arakeis added

#6 @ryan
17 years ago

  • Milestone 2.93.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 3.0Future 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
14 years ago

  • Component QueryTemplate

Closed #10745 as a duplicate.

#10 @SergeyBiryukov
14 years ago

  • Description modified (diff)

#11 @nacin
13 years ago

  • Component TemplatePosts, Post Types
  • Focuses template added

#12 @ryan
12 years ago

  • Owner ryan removed
  • Status newassigned

#13 @wonderboymusic
11 years ago

  • Keywords needs-refresh added

#14 @SergeyBiryukov
6 years ago

#52313 was marked as a duplicate.

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


11 months ago

#17 @SirLouen
11 months ago

  • Keywords has-patch needs-testing removed
  • Resolutionworksforme
  • Status assignedclosed

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.