| 1947 | |
| 1948 | /** |
| 1949 | * Retrieve the parent post ID. |
| 1950 | * |
| 1951 | * @since 5.3.0 |
| 1952 | * |
| 1953 | * @param int|WP_Post|null $post_id Optional. Post ID or post object. |
| 1954 | * |
| 1955 | * @return int |
| 1956 | */ |
| 1957 | function get_post_parent( $post_id = null ) { |
| 1958 | $post = get_post( $post_id ); |
| 1959 | |
| 1960 | if ( empty( $post ) ) { |
| 1961 | return 0; |
| 1962 | } |
| 1963 | |
| 1964 | return $post->post_parent; |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Whether the post has a parent post. |
| 1969 | * |
| 1970 | * @since 5.3.0 |
| 1971 | * |
| 1972 | * @param int|WP_Post|null $post_id Optional. Post ID or post object. |
| 1973 | * |
| 1974 | * @return int |
| 1975 | */ |
| 1976 | function has_post_parent( $post_id = null ) { |
| 1977 | return (bool) get_post_parent( $post_id ); |
| 1978 | } |