How to get the post’s parent ID?

WordPress 5.7 introduces a new helper function to more easily fetch the parent post’s ID:
get_post_parent()

This can also be used in conjunction with has_post_parent(), so you could have something like looks like:

<?php if ( has_post_parent() ) : ?>
    <a href="<?php the_permalink( get_post_parent() ); ?>">
        <?php
        echo sprintf(
            esc_html__( 'Back to parent page: %s', 'text-domain' ),
            get_the_title( get_post_parent() )
        );
        ?>
    </a>
<?php endif; ?>

Note that these functions accept a “child post ID” as a parameter, which defaults to the current post.

https://make.wordpress.org/core/2021/02/10/introducing-new-post-parent-related-functions-in-wordpress-5-7/