I had created a topic discussing how to create an interface to add new posts to a Wordpress blog using PHP and XML-RPC. It was something I had needed for work. Unfortunately for many of my site visitors and readers from Google, I never had the need to edit an article, but many of them did. I no longer had a development installation of Wordpress and I don't particularly like Wordpress (due to its spaghetti like codebase).

The people have spoken though, and I have listened. I reinstalled Wordpress to see if I could get an edit action to work. This is a two step process, you must first get the contents of the post, and then submit the edited version back to Wordpress. The tricky part here is modifying the date field.

If you haven't read my first post on adding a new post in Wordpress with PHP and XML-RPC, you'll want to read that. There I cover all of the basics you would be better off knowing before tackling an edit straight from this code (it won't make much sense otherwise).

Using the same IXR library that I used in the post creation article, we'll use a similar approach to retrieve an article. There are two ways to get article information - if we know the ID of the article we can simply use metaWeblog.getPost, or we can get a list of recent posts (with a maximum limit of - I believe - 15) using metaWeblog.getRecentPosts.

A simple print_r() of $response will give me the following:

As I said, the tricky part here is the date. If we want to modify the date, we need to supply the IXR_Client object an IXR_Date object. But how do you do that? Well, looking at the IXR class code, the constructor needs to be supplied either an ISO date, or a timestamp. Since it's easy to supply a timestamp, I'll do that for this example.

I used strtotime() with "now" as the passed parameter so that we'll get back a timestamp for the current time. This is just an example, make it fit to your needs. I've also put in the necessary data required for the $content variable, and used most of the variables from the previous metaWeblog.getPost request. So...now we simply call the actual query for metaWeblog.editPost:


That's it. metaWeblog.editPost is pretty easy as long as you have the right data being sent to it.

Note: I will NOT be indulging questions pertaining to anything beyond the scope of this article, such as custom fields or any type of plugin that modifies the standard behavior.

Trackbacks


Trackback specific URI for this entry
    No Trackbacks

Comments


    #1 Katie on 05/10/10 at 03:06 AM [Reply]
    Thank you Brendon, i tried Edit post option and fortunately it worked out for me. Thanks anyways for sending an email about this post. I love it.

    Thanks.
    #1.1 Brendon Kozlowski on 05/10/10 at 08:13 AM [Reply]
    I'm glad you got it working afterall and that you didn't have to wait for this. Either way, hopefully your fulfilled request (and the requests of others) from my other topic will be of use to others. Thank you for commenting!
    #2 Michel on 06/05/11 at 01:34 PM [Reply]
    Hello,
    Inspired by your articles, but a little hungry with recent WP 3.1, I publish this post relating my recent experiences with xmlrpc protocol between two WordPress site... and how to create post with attachments...

    http://dev.xiligroup.com/?p=2091

    Hope it will be useful for readers..

    Best regards
    Michel of dev.xiligroup team
    #2.1 Brendon Kozlowski on 06/08/11 at 12:27 PM [Reply]
    Thank you for offering to share your experience and results with us, Michel. Cheers!

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

BBCode format allowed