Make WordPress Core

Opened 12 years ago

Closed 6 years ago

#13412 closed enhancement (fixed)

Parent parameter returns no results in get_pages()

Reported by: jda10487 Owned by:
Milestone: 3.7 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description (last modified by nofearinc)

The get_pages() function in post.php returns no results when parent != 0, rather than returning the pages that are children of the immediate page.

Given page ID 30, which has 3 child pages, calling get_pages('parent=30') will return nothing.

The problem is in the following lines (line ~2600 at the time of writing):

if ( $child_of || $hierarchical )
	$pages = & get_page_children($child_of, $pages);

Hierarchical, by default, is set to true, this this conditional will typically be true. When it does so, it filters out all of the pages retrieved up to this point and, by the time it returns, there are no pages left.

The quick work-around I'm currently using is to call the following instead:


overriding the default value so that conditional doesn't execute.

The one exception to this is that calling get_pages('parent=0') should function even with this bug.

Change History (5)

#1 @jda10487
12 years ago

Noted behavior here:

If corrected, the documentation should be updated.

#2 @nacin
12 years ago

  • Milestone changed from Unassigned to Future Release
  • Type changed from defect (bug) to enhancement

From Codex: "Also note that the hierarchical parameter must be set to 0 (false) -- which is not default -- or else no results will be returned for any page other than the root (ID=0)."

#3 @nofearinc
8 years ago

  • Description modified (diff)

#4 @nacin
8 years ago

  • Component changed from General to Post Types

#5 @wonderboymusic
6 years ago

  • Milestone changed from Future Release to 3.7
  • Resolution set to fixed
  • Status changed from new to closed

Fixed for you here [25245]

Note: See TracTickets for help on using tickets.