duanpanzhu2910 2015-05-15 06:54
浏览 54

将s3图像设置为wordpress帖子中的特色图像,同时以编程方式从外部源发布帖子

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.

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.

  • 写回答

1条回答 默认 最新

  • dsqve08622 2015-11-14 07:22
    关注

    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>');
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度