WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#5742 closed enhancement (invalid)

add child_of to query_posts

Reported by: strider72 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: needs-patch
Focuses: Cc:

Description

IT would be a nice, simple enhancement to core if we allowed a "child_of" parameter in query_posts. This would add a lot of flexibility to themes and such, making it easier to make index pages for site sections.

(Disclaimer -- I cribbed the code straight from westi's plugin :-) )

Attachments (1)

wp_child_of.diff (2.0 KB) - added by strider72 11 years ago.
Adds "child_of" parameter to query_posts

Download all attachments as: .zip

Change History (9)

@strider72
11 years ago

Adds "child_of" parameter to query_posts

#1 @Denis-de-Bernardy
10 years ago

still current?

#2 @strider72
10 years ago

The method still works, as I still use the plugin from which I borrowed the code.

#3 @Denis-de-Bernardy
10 years ago

patch is broken though

#4 @filosofo
10 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from new to closed

Actually, "child_of" is the wrong name for this parameter, if we're going to be consistent with how it's used elsewhere in WP.

  • "child_of" - Selecting the "child_of" X should return all the descendants of X (children, grandchildren, great-grandchilren, etc.).
  • "parent" - Selecting the "parent" X should return just the immediate, first-generation children of X, not all descendants.

Patch shows a query for "parent," which we can get already with the "post_parent" parameter.

I'm closing as invalid because we can already do what the patch does with "post_parent."

#5 follow-up: @strider72
10 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone set to 2.9
  • Resolution invalid deleted
  • Status changed from closed to reopened

filosofo -- Either I am misunderstanding you, or you are misunderstanding this patch.

post_parent works in different circumstances. This patch allows you to use the following in a template:

query_posts('child_of='.$post->ID);

I use it (for example) for a "section index" page -- I create a loop that lists just the children of the current page. if I can do this somehow with "post_parent", could you please give a simple example?

This won't be going to 2.8 anyway (feature freeze), so I'll update the patch for 2.9 after 2.8 is released.

If appropriate, I can change the parameter from "child_of" to "parent", though it seems a bit unintuitive to use "parent" as "this is the parent of...." (But if that's the standard in WP, so be it.)

#6 in reply to: ↑ 5 @filosofo
10 years ago

Replying to strider72:

filosofo -- Either I am misunderstanding you, or you are misunderstanding this patch.

post_parent works in different circumstances. This patch allows you to use the following in a template:

query_posts('child_of='.$post->ID);

I use it (for example) for a "section index" page -- I create a loop that lists just the children of the current page. if I can do this somehow with "post_parent", could you please give a simple example?

query_posts(array(
'post_parent' => $post->ID,
'post_status' => 'any',
'post_type' => 'any'
));

though it seems a bit unintuitive to use "parent" as "this is the parent of...." (But if that's the standard in WP, so be it.)

I agree. I wish whoever had come up with these had used more explicit names, such as "descendant_of" or "parent_of". But that's what we're stuck with.

#7 @strider72
10 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Huh. That does indeed work. I'm a bit confused though, because looking at the core code, I don't see "post_parent" in the $public_query_vars array (in includes/classes.php). I thought that array had all the parameters for query_posts() -- thus my confusion.

Thanks filosofo -- i just eliminated one plugin from my site. :)

#8 @Denis-de-Bernardy
10 years ago

  • Milestone 2.9 deleted
Note: See TracTickets for help on using tickets.