Home > Code Snippets, PHP, Tips > Posting to wordpress using php cli and xmlrpc

Posting to wordpress using php cli and xmlrpc

February 8th, 2010 Leave a comment Go to comments

A reader once asked me if I could build a command line tool which takes title from one file, and content from another file to create wordpress post. I tried, which finally gave an outline to this script. I dont think that this is very high fly, but for those whom the xmlrpc is mumbo, this might be somthing worth looking into.

The requests are encoded into xml format using xmlrpc_encode_request, and responses are decoded using xmlrpc_decode. The response is tested using xmlrpc_is_fault. The transport is handled using curl methods. Sorry I am poor at code commenting.

Those who are trying the code, please dont forget to check and customize the configuration which is on line 129 for the login details, and line 26-33, where the categories are cached into the system.

Download the files: XML WpPost (1159)

Categories: Code Snippets, PHP, Tips Tags: , ,
  1. Petra
    March 11th, 2010 at 07:15 | #1

    Can´t download XML WpPost.
    And is there an example, how to use?


  2. March 12th, 2010 at 08:13 | #2

    I think it is due to some browsers or some other network problems, that the content is opened in the browser. Just try right click and choose save link as.

  3. Awmen
    January 30th, 2011 at 23:10 | #3

    Kinda silly question but How should I put the categories on lines 26-33?

  4. Awmen
    January 31st, 2011 at 10:59 | #4

    Ok, it resulted that I haven’t installed php5-curl and php5-xmlrpc now the script works and posts get published but all of them goes to Uncategorized instead of the category I tell the script, additionally I get this error when executing the script:

    PHP Warning: xmlrpc_is_fault() expects parameter 1 to be array, integer given in xml_wppost.php on line 54

  5. March 6th, 2011 at 19:37 | #5

    @Awmen I think you are passing the category as string, it should be passed as array, and the categories should exist. I got the same some time back when I tried to post to a non existent category

  6. May 26th, 2011 at 04:46 | #6

    I have a php website that integrates wordpress – using it as a blog.
    I want to use websites comments code and database to collect comments,
    but when I use wp-comments-post.php, it goes to the blog pages.

  7. July 19th, 2011 at 14:13 | #7

    I am not fully understanding your query, though I do think that you need to collect feedback, but don’t wish to publish that on the post page. In that case you need to edit the templates, such that the comments form is shown, but approved comments are not displayed.

  8. July 24th, 2012 at 07:47 | #8

    When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three emails with the same comment.
    Is there any way you can remove people from that service?

  9. Sibyl Ying
    January 14th, 2013 at 20:41 | #9

    Nice blog here. Also your website a lot up fast. What web host are you the usage of? Can I get your associate hyperlink for your host? I desire my site loaded up as quickly as yours lol

  1. No trackbacks yet.

− three = two