Posted By

BoNzO on 03/21/09


Tagged

wordpress


Versions (?)

Categoria padre di un post in Wordpress


 / Published in: PHP
 

  1. /**
  2.  * Ritorna la categoria padre di un post
  3.  *
  4.  * @return
  5.  * @param object $post_id
  6.  */
  7. function get_parent_category( $post_id ) {
  8. $cats = wp_get_object_terms($post_id, 'category', array('fields' => 'all') );
  9. foreach( $cats as $key => $cat ) if( $cat->parent == 0) return $cat;
  10. return null;
  11. }

Report this snippet  

You need to login to post a comment.