zachfeldman / rubypress

Ruby interface for the WordPress XMLRPC API. Follows standard XML-RPC Documentation closely.
201 stars 55 forks source link

Add new post with metadata #42

Closed funkenstrahlen closed 9 years ago

funkenstrahlen commented 9 years ago

I currently try to create new wordpress posts with metadata as described here: https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/new/

Array of metadata objects containing the following properties: key (metadata key), id (meta ID), previous_value (if set, the action will only occur for the provided previous value), value (the new value to set the meta to), operation (the operation to perform: update or add; defaults to update). All unprotected meta keys are available by default for read requests. Both unprotected and protected meta keys are avaiable for authenticated requests with proper capabilities. Protected meta keys can be made available with the rest_api_allowed_public_metadata filter.

It uses the wordpress custom fields: https://codex.wordpress.org/Custom_Fields

However I do not know how to do that with rubypress.

    wp.newPost( :blog_id => "0", # 0 unless using WP Multi-Site, then use the blog id
                :content => {
                             :post_status  => "draft",
                             :post_date    => entry.published,
                             :post_content => entry.content,
                             :post_title   => entry.title,
                             :post_name    => post_name,
                             :post_type    => "podcast",
                             :post_author  => 1
                             :metadata     => [] # what do I have to write here?
                             }
                )

Can you tell me how to do that? Is that even possible with rubypress? I do not understand how wordpress wants the "objects" to be encoded.

zachfeldman commented 9 years ago

Hey there, why don't you just try it? Sounds like you need to pass in an array of hashes. Rubypress deep merges any passed in objects.

funkenstrahlen commented 9 years ago

Ok I try hashes. I am just unsure what they mean with objects in the docu. I will close this if I managed to get it working :)

chan0123 commented 6 years ago

in case if someone want the example, the metadata will take array of hashes as follows:

:metadata => [{:key=>"somekey", :value=>"somevalue"}]