Given a post represented by a post object $p
, you can find out if post 31 is the parent via:
if($p->post_parent == 31){
// it is!
} else {
// it isn't
}
To figure out the children, something like:
$posts = get_posts(array(
'post_parent' => $p->ID,
'post_type' => $p->post_type
));
// if there are children, they will be contained in `$posts`
Finally, to determine how many levels deep down the hierarchy you are, you will need to recurse up the hierarchy $p->parent_post == 0
, and then count how many times you needed to do that.
e.g.
$level = 1;
while($parent->parent_post != 0){
$level++;
$parent = get_post($parent->parent_post);
}
Related Posts:
- Custom post types with custom directories
- Custom Path/Folder behind a custom post type
- How to produce a sub-page-system in WordPress
- Need folder for CPT templates for eg: single-{post_type}.php
- Restrict custom post type to only site administrator role
- Prevent pre_get_posts filter on specific post type
- How to force one column layout on custom post type edit page?
- Multiple post types – share same ReWrite slug?
- Search multiple custom fields by using meta_query
- How to Remove Certain Screen Options and Table Columns from post type in wp_list_table?
- How does one delete orphan custom post type?
- Redirect after deleting post and keep track of pagination
- Localization For Two Different Regions/Domains with the Same Language
- Add comments meta fields to comments metabox on post edit screen
- remove_action conditionally for Custom Post Type
- Assigning a role to a specific custom post type (and ignoring other post types)
- Display posts in random post types
- Custom Post Type by user
- Interesting Custom Post Type Slug with Taxonomy and Custom Field
- Custom Post Type post ordering not working
- Get all posts WHERE custom_field is LIKE value
- How do you output custom code between posts in the loop?
- Best practice for adding posts in bulk
- WP 3.1 getting tax_query to work in query_posts()
- wp_get_nav_menu_items wp-admin/customize.php problem
- Impossible to get Attachments Outside WordPress?
- How does the $post_type global variable work?
- Assigning the same custom meta box to multiple post types
- Is it possible to place custom post type files inside a folder in theme directory?
- How to structure a site with product variations pages?
- Getting rid of /my_custom_post_type/ in the single view URL
- Custom Post Type – List all attachments on Edit Screen
- Custom Page that comes with preloaded content for the user
- will post_id ever change? Can I safely use post_id for custom queries?
- Is it possible to create relational metabox values in a custom post?
- Custom Post Type Query for Sidebar Doesn’t Work on Front Page
- Meta query for custom post type ignored in main query
- How do I move/order posts with a tag to the end?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Update postmeta Parent when post_status child change
- WP_Query custom post type query not showing the exact post type
- Send notification to the admin when new custom post is submitted
- How do i search authors from search form using author’s name
- How to give all CPT a folder automatically based on their slug
- don’t publish custom post type post if a meta data field isn’t valid
- Detect inside a custom query the kind of post type to assign custom classes
- How do you make a custom post type items automatically delete items 3 months after publication?
- custom post data – how to
- How to display custom field value on page?
- Add an Outside Wrapper to my Header and Make it Full Width
- How to add a sub directory to WordPress single posts without affecting other post types?
- WordPress custom API endpoint – how to make the request more flexible
- How to Create a Separate Page for Blog Posts in WordPress
- Add custom columns in custom post type browse page
- Create custom WP_List_Table in post_type
- How to hide a custom field from admin?
- Get terms for a specfic post from multiple taxonomies in custom post type
- CMB select with data from CPT
- Building a Data Intensive Website with WordPress
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- Yelp-style geographic directory plugin?
- how to use custom post types collectively integrated with each other
- Why doesnt my tag page populate with this custom post type?
- Problem with customize page cached in WordPress.com [closed]
- Multiple categories assigned to a single product breaking the breadcrumb
- Adding a location field to buddypress activity
- Create API’s for custom-post types & custom queries using REST or Graphql
- custom post type and user post count shortcode
- How can I assign multiple parents to CPT?
- Getting 404 on child page with pre_get_posts() on custom posts
- CPT: multiple loops with different terms
- Stored meta from attachment, video length?
- Limit posts per page depending on the size of a div?
- Delete Post by User
- save_post affect creation and deletion
- Set a static page as a user profile page?
- Problem to get the link of the default ‘post’ post type like the orther custom types
- WordPress query posts by custom post type not workng
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- How to keep a CPT stick to specific position?
- WP_Query for CPT with filter by another WP_Query
- Get data from custom post type to another custom post type?
- Using get_terms() as shortcode attribute
- Turn post into simple slideshow
- Problems with a custom meta_box
- Multiple Block Quotes without using HTML
- How to apply order on custom taxonomy and custom meta key on custom post type
- How can i display on front page a movie that is atached in a post type
- Data won’t save on a straightforward metabox, what am I missing?
- Custom post type functions.php if statement on action
- Query multiple post of which one by taxonomy
- How to make a template for a specific post of a custom post type?
- Bulk update custom post types
- Set a Custom Post Type as a Homepage
- Slideshow/Gallery plugin based on WP Core Gallery [closed]
- How to create a job post by email parsing? [closed]
- ACF select box css color change
- Creating post custom field text area
- Delete old thumbnail when updating new
- How to automate the creation of advanced layout article/post