| | 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 | return ! empty( $post ) ? $post->post_parent : 0; |
| | 1960 | } |
| | 1961 | |
| | 1962 | /** |
| | 1963 | * Whether the post has a parent post. |
| | 1964 | * |
| | 1965 | * @since 5.3.0 |
| | 1966 | * |
| | 1967 | * @param int|WP_Post|null $post_id Optional. Post ID or post object. |
| | 1968 | * |
| | 1969 | * @return int |
| | 1970 | */ |
| | 1971 | function has_post_parent( $post_id = null ) { |
| | 1972 | return (bool) get_post_parent( $post_id ); |
| | 1973 | } |