在 publish_post Wordpress 上获取 Yoast 插件信息

Get Yoast Plugin infos on publish_post Wordpress

我正在尝试获取有关 publish_post 的 yoast 插件信息,我知道 get_post_meta 在 publish_post 之后被触发,但不知道如何获取发布的值publish_post...我认为通过获取 $_POST 值它可以工作,但似乎不行。 到目前为止我的代码是:

add_action( 'publish_post', 'post_published_notification');
function post_published_notification( $ID, $post ) {
            $url = $post->post_name;
            $yoast_seo_title = get_post_meta($ID, '_yoast_wpseo_title', true);
            $yoast_meta_desc = get_post_meta($ID, '_yoast_wpseo_metadesc', true);
}

在此先感谢您的帮助。

编辑:无法挂钩 save_post 否则它会被触发两次...

对自己的回答:

add_action( 'publish_post', 'post_published_notification');
function post_published_notification( $ID, $post ) {
            $url = $post->post_name;
            if(isset($_POST["yoast_wpseo_title"]) && !empty($_POST["yoast_wpseo_title"])){ 
                $yoast_seo_title = $_POST["yoast_wpseo_title"];
            }
            if(isset($_POST["yoast_wpseo_metadesc"]) && !empty($_POST["yoast_wpseo_metadesc"])){ 
                $yoast_meta_desc = $_POST["yoast_wpseo_metadesc"];
            }
}