[wp-trac] [WordPress Trac] #22471: get_category_parents problem with sub-categories (all WP Versions - to 3.5 beta)

WordPress Trac noreply at wordpress.org
Fri Nov 16 11:03:26 UTC 2012


#22471: get_category_parents problem with sub-categories (all WP Versions - to 3.5
beta)
--------------------------+------------------------------
 Reporter:  wpweaver      |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  1.2
 Severity:  normal        |  Resolution:  worksforme
 Keywords:  close         |
--------------------------+------------------------------
Changes (by c3mdigital):

 * keywords:   => close
 * status:  new => closed
 * resolution:   => worksforme


Comment:

 get_category_parents works as expected.  It retrieves a child categories
 parents. Your issue is how the category id that gets passed to the
 function is retrieved.  If you are using get_the_category() the term array
 returned will be ordered alphabetically ( see wp_get_object_terms(); )

 {{{
 add_filter( 'the_content', 'test_get_cat_parents' );
 function test_get_cat_parents( $content ) {
     $cats = get_the_category();

     return $content. '<br>' . get_category_parents( $cats[0]->term_id );
  }
 }}}

 This will return only photography for post 2.  If the array index is
 changed from 0 to 1 then then it will return photography and wedding
 because the id passed to get_category_parents will be the actual child
 term.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22471#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list