Wordpress category hierarchy


/ Published in: PHP
Save to your folder(s)

Returns Wordpress categories as a hierarchical object (i.e. categories with subcategories)


Copy this code and paste it in your HTML
  1. function get_cat_hierchy($parent,$args){
  2.  
  3. $cats = get_categories($args);
  4. $ret = new stdClass;
  5.  
  6. foreach($cats as $cat){
  7. if($cat->parent==$parent){
  8. $id = $cat->cat_ID;
  9. $ret->$id = $cat;
  10. $ret->$id->children = get_cat_hierchy($id,$args);
  11. }
  12. }
  13.  
  14. return $ret;
  15. }

URL: http://wordpress.org/support/topic/get_categories-hierarchy-not-working

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.