set s3 image as a featured image in wordpress post while posting the post programatically from an external source

I am pretty much new to wordpress. My requirement is that i need to make a post from an external source using ajax to wordpress site. The post data merely contain “posttitle,description,etc…” and an “imageurl” which is pre-uploaded to amazon s3.
I am succcessfully able to post the data using the following reference
http://codex.wordpress.org/Function_Reference/wp_insert_post#Example

but i need to save the s3 url (external image) to worpress post tables and show it as a featured image without again uploading to wordpress server.

Read More

To figure out how the images are being saved, I logged into wp admin and created a post with featured image, searched wp tables for image path and it is saving image relative path in ‘postmeta’ table as below.
enter image description here

The images are stored with relative reference path.Then i thought even if i forcefully insert s3 url (which is absolute),wordpress might not be able to recoginize it as it might always be searching for local files.How do i achieve inserting s3 urls into wordpress tables and make them show up in my posts.
I searched everywhere but couldn’t find solution for this particular case.
Any help is appreciated. Thanks in advance.

Related posts

1 comment

  1. You can use a absolute path in the guid field in the posts table for the featured image with post_type set to attachment.

    The image is set to Featured for a given post by adding it to the postmeta table with the post ID and the featured image post ID and meta_key = _thumbnail_id.

    INSERT INTO $wp->post 
        (post_type, guid, status, post_mime_type) 
    VALUES 
        ('attachment', '<imageUrl>', 'publish', 'image/jpeg');
    
    INSERT INTO $wp->postmeta 
        (meta_value, meta_key, post_id) 
    VALUES 
        ('<imagePostID>', '_thumbnail_id', '<postID>');
    

Comments are closed.