Reputation: 348
In wordpress whenever new blog post is created all post details need to be send to third party api. I'm using save_post hook for this but not sure whether it's getting called or not This is what i've done so far
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 ) );
}
Not sure how to log or debug in wordpress.Any help would be appericiated Thanks in advance
Upvotes: 0
Views: 2876
Reputation: 348
Solve the problem by taking the alternative hook for save_post. Used publish_post instead & with higher priority & it worked
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);
Upvotes: 2