2016-05-13 58 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"]; 
      } 
}