WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 3 years ago

#8050 closed enhancement (wontfix)

is_child()

Reported by: youngmicroserf Owned by: westi
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: template Cc:

Description

Is there any reason why there is no native is_child(direct,in_tree) function for hierarchical structures in WP (like pages, categories, custom hierarchical taxonomies)? There's a (partly) working plugin available at

http://2pt3.com/post/wordpress-plugins/

but I think this amounts to a core functionality, particularly for people using WP as a hierarchical CMS.

Attachments (2)

8050.patch (698 bytes) - added by kurtpayne 8 years ago.
has_child_relationship()
8050.1.patch (716 bytes) - added by kurtpayne 8 years ago.
Documenting return type

Download all attachments as: .zip

Change History (21)

#1 @westi
11 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

#2 @FFEMTcJ
10 years ago

  • Milestone changed from 2.8 to Future Release

#3 @Denis-de-Bernardy
10 years ago

  • Component changed from General to Template

#4 @youngmicroserf
9 years ago

  • Milestone changed from Future Release to 3.0

Bumping this up.

#5 @dd32
9 years ago

  • Keywords needs-patch added; is_child CMS selection removed
  • Milestone changed from 3.0 to 3.1

Unfortunately this has missed the boat for 3.0 as we're in a feature freeze.

I'm not setting this to 3.1 due to there not being a patch. If someone provides a patch, it may be in 3.1.

#6 @dd32
9 years ago

...And there i go setting it to 3.1 anyway... I'll leave it in 3.1 for now.

#7 @scribu
9 years ago

Related: #12443

#8 @scribu
9 years ago

If we get #12443 in, is_child() would be as simple as:

function is_child( $child, $parent, $object_type ) {
    return in_array( $parent, get_ancestors( $child, $object_type ) );
}

#9 @voyagerfan5761
9 years ago

  • Cc WordPress@… added

#10 @filosofo
9 years ago

There's no need to have both is_descendant and is_ancestor, right?

#11 @scribu
9 years ago

No, they're the same, except the parameter order would be different.

#12 @scribu
9 years ago

I was about to make cat_is_ancestor_of() use get_ancestors().

Then I realized that cat_is_ancestor_of(), as it is now, will stop once it finds a match, whereas get_ancestors() wouldn't.

So yeah, disregard comment:8

#13 @nacin
9 years ago

  • Milestone changed from Awaiting Triage to Future Release

Still just needs a patch.

#14 @nacin
9 years ago

That said, we should probably avoid is_* as it isn't a conditional tag.

@kurtpayne
8 years ago

has_child_relationship()

#15 @kurtpayne
8 years ago

  • Cc kpayne@… added
  • Keywords has-patch added; needs-patch removed

@kurtpayne
8 years ago

Documenting return type

This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.


6 years ago

#17 @nacin
6 years ago

  • Component changed from Template to General
  • Focuses template added

#18 @ericlewis
5 years ago

I can't imagine using this myself - anyone care to share a use-case?

#19 @swissspidy
3 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from accepted to closed

I can't imagine using this myself - anyone care to share a use-case?

Agreed. Especially since it's now just a 1-liner.

Closing as wontfix because of a lack of traction. Feel free to reopen when some valid use cases for themes, plugins, and/or core emerge.

Note: See TracTickets for help on using tickets.