Posted By

rliverman on 04/04/12


Tagged

php wordpress recursive id Parent grandparent


Versions (?)

Get Top Parent or Grandparent ID Wordpress


 / Published in: PHP
 

URL: http://andyweigel.com/blog/wordpress-how-tos/great-grand-parent-ids-in-wordpress/44

From 'Andy' in the comments.

  1. function get_top_ancestor($id){
  2. $current = get_post($id);
  3. if(!$current->post_parent){
  4. return $current->ID;
  5. } else {
  6. return get_top_ancestor($current->post_parent);
  7. }
  8. }

Report this snippet  

You need to login to post a comment.