duncantl / RWordPress

http://www.omegahat.org/RWordPress
26 stars 23 forks source link

Modify Custom Fields when Publishing Post? #6

Open yogat3ch opened 5 years ago

yogat3ch commented 5 years ago

I've been using RWordpress to upload image files to a blog for some time and I'd like to take it to the next level and start publishing the entire post directly through R. I've been happy with the results so far in getting the content and images up - however, there's custom styles that need to go into the head tag on each post. I've manage to discover the id & key of this meta field that holds the custom head content where the css styles go, but I'm unsure as to how to declare the options to get it into the post properly.

Reprex

I've declared the WordpressURL, and WordpressLogin global options and other functionality with RWordpress seems to work fine.

I'm using editPost on the Hello World! (postid = 1) post for testing the modification of the head custom code meta field. Content is a mandatory field so I've just added filler for that value. The id and key are the actual ones for the post. I tried running the code below:

RWordPress::editPost(postid = 1, content = "blah test", method = "wp.editPost", .args = list(custom_fields = list(id = 9697, key = "aFhfc_head_code", value = "text/css test")))

and this is the traceback and error :

Error: faultCode: 400 faultString: Insufficient arguments passed to this XML-RPC method.
7.
stop(e)
6.
convertToR(xmlParse(node, asText = TRUE))
5.
convertToR(xmlParse(node, asText = TRUE))
4.
convertToR(ans)
3.
convertToR(ans)
2.
xml.rpc(.server, "metaWeblog.editPost", as.character(postid), names(login), as.character(login), content, as.logical(publish), ...)
1.
RWordPress::editPost(postid = 1, content = "blah test", method = "wp.editPost", .args = list(custom_fields = list(id = 9697, key = "aFhfc_head_code", value = "text/css test")))

Furthermore, I'm wondering if this can be used as is with newPost, or if it need be adapted for that method?

Any ideas how to resolve this issue?