2016-05-13 59 views
2

我试图让publish_post yoast插件的相关信息Yoast插件的相关信息,我知道get_post_meta是publish_post解雇后却看不到我怎么能抢上publish_post的公布值...我想通过获得$ _POST值它可以工作,但似乎没有。 到目前为止我的代码是:获取有关publish_post WordPress的

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否则会被解雇两次...

回答

2

回答自己:

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"]; 
      } 
}