How to create new post with photo attached in WordPress using XMLRPC?

前端 未结 6 2271
忘了有多久
忘了有多久 2020-12-15 13:44

Anyone knows how to create new post with photo attached in WordPress using XMLRPC?

I am able to create new post and upload new picture separately,

6条回答
  •  孤街浪徒
    2020-12-15 14:01

    I had to do this several months ago. It is possible but not only is it hacky and undocumented I had to dig through wordpress source to figure it out. What I wrote up way back then:

    One thing that was absolutely un-documented was a method to attach an image to a post. After some digging I found attach_uploads() which is a function that wordpress calls every time a post is created or edited over xml-rpc. What it does is search through the list of un-attached media objects and see if the new/edited post contains a link to them. Since I was trying to attach images so that the theme’s gallery would use them I didn’t necessarily want to link to the images within the post, nor did I want to edit wordpress. So what I ended up doing was including the image url within an html comment. -- danieru.com

    Like I said messy but I searched high and low for a better method and I'm reasonably sure that none exists.

提交回复
热议问题