public static function get_top_level_parent_id($post = null)
    {
        if (\is_search() || \is_404()) {
            return null;
        }

        switch ($post) {
            // No post has been set, so use global.
            case null:
                global $post;

            // The post ID has been provided.
            case \is_int($post):
                $post = \get_post($post);

            // A WP_Post was provided.
            case \is_object($post):
                $ancestors = $post->ancestors;
                break;

            case \is_array($post):
                $ancestors = $post['ancestors'];
                break;
        }

        if (isset($ancestors) && ! empty($ancestors)) {
            return (int) \end($ancestors);
        } else {
            return (int) $post->ID;
        }
    }