wp_get_post_parent_id

Return the post's parent's post_ID.

Description

(int|false) wp_get_post_parent_id( (int) $post_ID ); 

Returns (int|false)

Post parent ID, otherwise false.

Parameters (1)

0. $post_id (int)
The post id.

Usage

  1. if ( !function_exists( 'wp_get_post_parent_id' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_get_post_parent_id($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function wp_get_post_parent_id( $post_ID ) { 
  2. $post = get_post( $post_ID ); 
  3. if ( !$post || is_wp_error( $post ) ) 
  4. return false; 
  5. return (int) $post->post_parent;