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.

3 Answers
3

you can use this snippet to get the first image of a post attachment id:

$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=" . $postID );
$attachment_id = $images[0]->ID;

Leave a Reply

Your email address will not be published. Required fields are marked *