Opened 5 years ago
Last modified 21 months ago
#8050 accepted enhancement
is_child()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Template | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | WordPress@…, kpayne@… |
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)
Change History (17)
comment:1
westi
— 5 years ago
- Owner changed from anonymous to westi
- Status changed from new to assigned
comment:3
Denis-de-Bernardy
— 4 years ago
- Component changed from General to Template
comment:4
youngmicroserf
— 3 years ago
- Milestone changed from Future Release to 3.0
comment:5
dd32
— 3 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.
comment:6
dd32
— 3 years ago
...And there i go setting it to 3.1 anyway... I'll leave it in 3.1 for now.
comment:8
scribu
— 3 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 ) );
}
comment:9
voyagerfan5761
— 3 years ago
- Cc WordPress@… added
comment:10
filosofo
— 3 years ago
There's no need to have both is_descendant and is_ancestor, right?
comment:11
scribu
— 3 years ago
No, they're the same, except the parameter order would be different.
comment:12
scribu
— 3 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
comment:13
nacin
— 3 years ago
- Milestone changed from Awaiting Triage to Future Release
Still just needs a patch.
comment:14
nacin
— 3 years ago
That said, we should probably avoid is_* as it isn't a conditional tag.
comment:15
kurtpayne
— 21 months ago
- Cc kpayne@… added
- Keywords has-patch added; needs-patch removed
Bumping this up.