Make WordPress Core

Opened 8 years ago

Closed 3 years ago

Last modified 3 years ago

#4948 closed enhancement (worksforme)

Category Parent/Child Tree

Reported by: iacas Owned by:
Milestone: Priority: low
Severity: minor Version: 2.2.3
Component: Taxonomy Keywords:
Focuses: Cc:


Short of building my own recursive function, I'd like WordPress to support a method to get a parent/child category ID tree. One function (get_category_parents) already does this except with the names of the categories. Another function, cat_is_ancestor_of in category.php appears to be usable, but I've been unable to get it to work.

In short, I'm trying to solve the problem of figuring out what top-most parent category a blog entry belongs to so that I can do some various things with CSS, sidebars, etc.


Change History (8)

#1 @ffemtcj
8 years ago

  • Milestone changed from 2.5 to 2.7

No Patch. Moved to 2.7

#2 @ryan
7 years ago

  • Milestone changed from 2.7 to 2.8

#3 @ryan
7 years ago

  • Milestone changed from 2.8 to Future Release

#4 @Denis-de-Bernardy
7 years ago

  • Component changed from General to Template

#5 @Denis-de-Bernardy
6 years ago

  • Keywords needs-patch added

#6 @Denis-de-Bernardy
6 years ago

  • Component changed from Template to Taxonomy
  • Priority changed from normal to low
  • Severity changed from normal to minor

isn't this what child_of does in get_terms() et al?

#7 @wonderboymusic
3 years ago

  • Keywords needs-patch removed
  • Resolution set to worksforme
  • Status changed from new to closed

Use this:

$tree = get_terms( 'category', array( 
   'get'      => 'all', 
   'orderby'  => 'id', 
   'fields'   => 'id=>parent' 
) );

You can pass 'slug' => 'my-slug' for context

#8 @helenyhou
3 years ago

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