我正在尝试获取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"];
}
}
关于php - 在publish_post WordPress上获取Yoast插件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37211918/