WordPress tutorials: Get post ancestors

Wpsnipp – Get post ancestors.When using WordPress as a CMS or building a breadcrumb, you often need to get the post ancestors. Today let’s have a look at how you can easily get post ancestors of a specific post.In order to get the post ancestors (also called parents) simply use the get_post_ancestors() function.

This function takes a single argument which can be either the post ID or post object, and return the ancestors IDs as an array.

 

 

 

<?php
 get_post_ancestors( $post );
 ?>

Leave a comment