I am using a plugin to forward photo posts from wordpress to a tumblr blog.
I have the following code:
//post blog to tumblr function postBlogTumblr($postID) { $URLServer = "http://www.tumblr.com/api/write"; $t_post = get_post($postID); $t_url = get_permalink($postID); $tumblr_data = unserialize(get_option("tumblr")); $postdata['email'] = $tumblr_data['tumblr_login_email']; $postdata['password'] = $tumblr_data['tumblr_login_pass']; $postdata['type'] = "photo"; $postdata['source'] = the_attachment_link($attachment_id); $postdata['caption'] = $t_post->post_title."(via adamblanchard.co.uk)"; $postdata['state'] = "published"; $postdata = http_build_query($postdata); $result = datapost($URLServer,$postdata); }
I believe I am using the right method on the $postdata[‘source’] line, but I am unsure how to go about getting the attachment id.
Any guidance would be greatly appreciated.
you can use this snippet to get the first image of a post attachment id:
this small code give you the first image from the post, if is inside the gallery of the post and is! the first image in the gallery of the post.
Play with my post about this possibilies and you find your best soltution.
If the image in question is attached to the post, then you can get the URL of the image using the
wp_get_attachment_url
function. (Read more in the codex here)