Set s3 image as display image in wordpress post when posting post programmatically from external source

I am very new to Wordpress. My requirement is that I need to render a post from an external source using ajax for a wordpress site. The postal data just contains "posttitle, description, etc." And "imageurl" which are pre-loaded on amazon s3.    I can post data successfully using the following link http://codex.wordpress.org/Function_Reference/wp_insert_post#Example

but I need to store the s3 url (external image) to move column to column and show it as display image without re-uploading to wordpress server.

To figure out how the images are saved, I went into wp admin and created a post with an image tag, looked up the wp tables for the image path, and stored the relative path of the image in the postmeta table as shown below. enter image description here

Images are saved with relative reference references. Then I thought that if I emphatically insert the s3 url (which is absolute) wordpress might not be able to repeat it as it can always look for local files. How can I achieve by inserting s3 url into wordpress tables and making them appear in my posts. I've searched everywhere but couldn't find a solution for this particular case. Any help is appreciated. Thanks in advance.

+3


source to share


1 answer


You can use an absolute path in a field guid

in the message table for the displayed image with post_type

set to attachment

.

The image is set to "Favorite" for this post by adding it to the table postmeta

with post id and post id with image image 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>');

      

0


source







All Articles