#15098 closed enhancement (fixed)
Can't add post with featured image using only XML-RPC
Reported by: | rvavruch | Owned by: | rvavruch |
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | |
Component: | XML-RPC | Keywords: | needs-patch mobile |
Focuses: | Cc: |
Description
AFAIK it is not possible to add a new post with a featured image using only XML-RPC. This is because the way to add a featured image with XML-RPC requires the wp_posts.id of the image to be used.
I have attached a patch based on trunk rev. 15775 which returns that id when performing a metaWeblog.newMediaObject. This id can then be used in the custom_fields of a metaWeblog.newPost to set the featured image (or _thumbnail_id).
Attachments (3)
Change History (24)
#1
@
14 years ago
_thumbnail_id is ideally internal. We shouldn't be expecting that to get passed around via XML-RPC to attach an image as a featured image.
#2
@
14 years ago
At the moment - unless I missed something - the only way to attach an image as a featured image through XML-RPC is by setting _thumbnail_id in the metaWeblog.newPost custom_fields parameter.
Should we open a new ticket to add a better method of setting the featured image?
It would be ideal if we could add the data required by "metaWeblog.newMediaObject" to a metaWeblog.newPost setting that as the featured image. That may break some standard though.
As it currently stands, the patch uploaded is a tiny change which solves the issue with the system as is.
#3
@
14 years ago
At a conceptual level I think this does much better being part of the metaWeblog.(new|edit)Post. Adding support for a 'featured_image' field would be enough. The post_id isn't a problem, check out the mw_newPost function, you'll see that we wait until after the new post has been created to process sticky options since those also require a valid post_id.
The data could then be exposed via the 'featured_image' field from metaWeblog.getPost.
#4
follow-up:
↓ 5
@
14 years ago
Strange, I don't seem to have wp-includes/class.wp-xmlrpc-server.php ..
Using Wordpres 3.0.4
But I'd really like this feature, trying to pull in posts daily with XML and trying to set a featured image is a giant pain!
#5
in reply to:
↑ 4
@
14 years ago
- Cc rvavruch added
- Owner set to rvavruch
- Status changed from new to assigned
Replying to Seanmcn:
Strange, I don't seem to have wp-includes/class.wp-xmlrpc-server.php ..
Using Wordpres 3.0.4
But I'd really like this feature, trying to pull in posts daily with XML and trying to set a featured image is a giant pain!
The file was moved in the latest (unreleased) version. The change still works for older released versions if you want to backport it, but you have to manually add it to the file "xmlrpc.php", on this line:
http://core.trac.wordpress.org/browser/tags/3.0.1/xmlrpc.php#L2832
#6
@
14 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
This should be promoted to a proper parameter for the api call as suggested above.
#7
@
13 years ago
- Cc cfinke added
I'd really like to be able to support featured images in ScribeFire, so I've added a patch that exposes featured images in the following ways:
- It includes the ID of each media object in the return value of getMediaLibrary.
- It accepts a featured_image field as input to mw_newPost and mw_editPost; the value is a media object ID.
- It returns as part of getRecentPosts a featured_image struct containing the ID and url values for the image.
- It removes the featured image if featured_image is not set as part of the request to mw_editPost. (This might not be optimal, since the moment that this change goes live, any posts edited via the API will lose their featured images unless the clients released a pre-emptive update to support this API change.)
This should be enough for clients to get/set/remove featured images; if you think it would be better to pass around URLs only, I can update the patch to reflect that.
#8
follow-up:
↓ 10
@
13 years ago
- Cc jbernal@… added
- Keywords mobile added
Added mobile tag, this is one of the top feature requests for mobile apps
#9
@
13 years ago
- Cc marko@… added
For setting the post thumbnail it probably would be better to use the core function set_post_thumbnail().
#10
in reply to:
↑ 8
@
13 years ago
- Cc dan@… added
Replying to koke:
Added mobile tag, this is one of the top feature requests for mobile apps
+1, a lot of requests for this coming in for WPAndroid.
#14
@
13 years ago
Added a new patch at #18429 that also fixes this issue. I only return the id at this moment. I do wonder if the url should be returned.
If so then we also should do that with the new wp post methods.
#15
@
13 years ago
Maybe I'm missing something, but looking at the latest patch, metaWeblog.newMediaObject doesn't return an attachment id, so you can't really set new image as featured
#17
@
13 years ago
Addressed koke's concern by returning the attachment ID in wp.uploadFile
and metaWeblog.newMediaObject
. Test in [UT588].
Return an id when performing a metaWeblog.newMediaObject