Opened 15 years ago
Closed 14 years ago
#12443 closed enhancement (fixed)
General get_ancestors() function
Reported by: | filosofo | Owned by: | filosofo |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Taxonomy | Keywords: | has-patch |
Focuses: | Cc: |
Description
get_ancestors([object_id], [object_type])
returns an array of the ancestor objects, starting from closest in hierarchy to highest.
This would be helpful for determining general inheritance in themes and plugins.
For example:
if ( in_array(123, get_ancestors(456, 'page') ) ) { // highlight a menu item, or query a particular set of objects }
Attachments (2)
Change History (16)
#3
@
14 years ago
- Milestone changed from 3.0 to Future Release
Let's get some unit tests? Punting due to feature freeze. Good for 3.1 IMO. Future for now.
#4
@
14 years ago
The proposed implementation of get_ancestors() will generate a lot of queries when you have deep nesting.
Also see #12908
#6
follow-up:
↓ 8
@
14 years ago
Replying to scribu:
The proposed implementation of get_ancestors() will generate a lot of queries when you have deep nesting.
How deep are you talking about, and how would that happen? I've never seen so many levels in categories that it would make a difference (in other words, more than a handful).
Also the object cache should help with that.
#7
@
14 years ago
Two more thoughts about that:
- If this is a live scenario, it would be a good use for MPTT
- It probably does interesting things to that taxonomy's admin, too.
#8
in reply to:
↑ 6
@
14 years ago
- Milestone changed from Future Release to 3.1
Replying to filosofo:
How deep are you talking about, and how would that happen? I've never seen so many levels in categories that it would make a difference (in other words, more than a handful).
You're probably right. The speed gained by having one query instead of 5 (for example) wouldn't justify the increased memory use.
I have unit tests for this, and I need to hit it a little more, but I wanted to get it in before feature freeze. I'll update shortly, once I have a few minutes to breathe.