Double posting from wordpress to tumblr using curl/php
Using a plugin in wordpress, I am attempting to pass the post info through the tumblr api to also post it to my tumblr blog.
Everything works apart from the fact I get a double post on the tumblr end, and I have no clue as to why.
function getImgSrc($postID) { if ( $attachments = get_children( array( 'post_type' => 'attachment', 'post_mime_type' => array('image'), 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID ))); foreach ($attachments as $attachment) { $t_source = wp_get_attachment_url( $attachment->ID ); } return $t_source; } //post blog to tumblr function postBlogTumblr($postID) { $URLServer = "http://www.tumblr.com/api/write"; $t_post = get_post($postID); $tumblr_data = unserialize(get_option("tumblr")); 开发者_JAVA百科 $postdata['email'] = $tumblr_data['tumblr_login_email']; $postdata['password'] = $tumblr_data['tumblr_login_pass']; $postdata['type'] = "photo"; $postdata['source'] = getImgSrc($postID); $postdata['caption'] = $t_post->post_title; $postdata['state'] = "published"; $postdata = http_build_query($postdata); $result = datapost($URLServer,$postdata); } function postBlogTumblr($postID) { $URLServer = "http://www.tumblr.com/api/write"; $t_post = get_post($postID); $tumblr_data = unserialize(get_option("tumblr")); $postdata['email'] = $tumblr_data['tumblr_login_email']; $postdata['password'] = $tumblr_data['tumblr_login_pass']; $postdata['type'] = "regular"; $postdata['title'] = $t_post->post_title; $postdata['body'] = $t_post->post_content; $postdata['state'] = "published"; $postdata = http_build_query($postdata); $result = datapost($URLServer,$postdata); }
Any guidance would be greatly appreciated.
From your posted code, I can only suspect you're getting a double post because you've duplicated the function postBlogTumblr()
.
精彩评论