2017-04-12 36 views
0

在wordpress創建新博客帖子時,所有帖子細節都需要發送給第三方api。我使用save_post掛鉤這一點,但不知道是否它獲取調用或不 這是我到目前爲止保存帖子時不會調用save_post鉤子

 add_action('save_post', 'new_blog_details_send'); 
    function new_blog_details_send($post_id) { 

    //getting blog post details// 
     $blog_title = get_the_title($post_id); 
     $blog_link = get_permalink($post_id); 
     $blog_text = get_post_field('post_content', $post_id); 

     ///Sending data to portal//// 
     $post_url = 'http://example.com/blog_update'; 
     $body = array(
       'blog_title' => $blog_title, 
       'blog_link' => $blog_link, 
       'blog_text' => $blog_text 
     ); 

     //error_log($body); 

     $request = new WP_Http(); 
     $response = $request->post($post_url, array('body' => $body)); 


    } 

不知道如何登錄或調試在wordpress.Any幫助將是完成appericiated提前致謝

+0

你檢查你的第三方是否使用靜態內容的工作? – sarath

+0

是的,它工作正常 –

+0

此代碼在functions.php中添加對不對?如果您在本地服務器中,則打印$響應並退出。然後通過保存帖子進行檢查。 – sarath

回答

1

通過採取替代掛鉤解決問題save_post。使用publish_post代替&具有較高優先級&它的工作

function new_blog_details_send($post_id) { 

    //getting blog post details// 
     $blog_title = get_the_title($post_id); 
     $blog_link = get_permalink($post_id); 
     $blog_text = get_post_field('post_content', $post_id); 

     ///Sending data to portal//// 
     $post_url = 'http://example.com/blog_update'; 
     $body = array(
       'blog_title' => $blog_title, 
       'blog_link' => $blog_link, 
       'blog_text' => $blog_text 
     ); 

     //error_log($body); 

     $request = new WP_Http(); 
     $response = $request->post($post_url, array('body' => $body)); 

} 
add_action('publish_post', 'new_blog_details_send',10,1); 
+0

我可以有你的電子郵件ID或電話號碼?我需要一些幫助.. –

+0

@Rituparnasonowal [email protected] –

相關問題