Editing WordPress “Pages” Via XML-RPC

WordPress‘s Pages open the door to using WP as a content management system. Unfortunately, Pages can’t be edited via XML-RPC blogging apps like Ecto. This might be a good thing, but I’m foolhardy enough to try working around it.

Here’s how:

Find a text editor you like and open up the wp-includes/functions-post.php file.

in the wp_get_recent_posts() function, change this:

$sql = “SELECT * FROM $wpdb->posts WHERE post_status IN ('publish', 'draft', 'private') ORDER BY post_date DESC $limit”;

to this:

$sql = “SELECT * FROM $wpdb->posts WHERE post_status IN ('publish', 'draft', 'private', 'static') ORDER BY post_date DESC $limit”;

Now, in the wp_update_post() function, look for this block of code:

// Escape data pulled from DB.
$post = add_magic_quotes($post);
extract($post);

and insert this block underneath it:

// XML-RPCs apps can't return “static” post status,
// so we have to work around it
$page_status = NULL;
if($post_status == “static”)
$page_status = “static”;

And follow that up by looking for this block:

// Now overwrite any changed values being passed in. These are
// already escaped.
extract($postarr);

and insert this block underneath it:

// set post_status static if this is a page
if($page_status)
$post_status = $page_status;

Fair warning: this works in my limited testing, but don’t blame me if you try it and it breaks something. You’d be a fool to mess with this on a live install, so don’t.

tags: , , , , , , , , , , , , , , , ,

24 thoughts on “Editing WordPress “Pages” Via XML-RPC

  1. So it seems this works fairly well. Except now my pages never finish loading. The page looks complete and according to my browser’s activity window, everything is loaded except the page itself. For instance it reads “13.5KB out of ?”. Any ideas?

  2. Pingback: Cd Chen’s webLog » Blog Archive » Editing WordPress “Pages” Via XML-RPC « MaisonBisson.com

  3. Anyone try this with WP2? I’m interested in trying it but that’s an awful lot of mucking around in core files so I’d rather someone else be the guinea pig. ;)

  4. Alrighty. No go with my install of WP2 and Marsedit. I’d try ecto but I think I used up my trial last year (never got around to actually do a blog)… But it was an XML-RPC error that Marsedit threw, so I’m reasonably sure it’s not unique to the program.

  5. It works a little with ecto and WP 2.0.1. I have to create a blank page in the admin panel, then I can edit it with ecto. This, at least, allows me to update pages quickly once they’re made. However, I have noticed that on some servers, my pages will hang the server’s php for a while if I edit a page too many times. Don’t know what’s up with that.

  6. Is it possible to post a working file with the version numers of WordPress and Ecto.

    [tags]Ecto, WordPress Pages,[/tags]

  7. Is it possible to post a working file with the version numers of WordPress and Ecto.

    [tags]Ecto, WordPress Pages[/tags]

  8. Pingback: Editing WordPress Pages Via XML-RPC - A Frog in the Valley - Technology Intelligence

  9. Pingback: trellis » Blog Archive » my brain is pouring out

  10. Hey, I just got this working with WP 2.0.4 and BlogsInHand. I had trouble figuring out where to put the last block, as the original text is not there AFAICS. I put it in the wp_update_post() function after the block starting:

    // Drafts shouldn’t be assigned a date unless explicitly done so by the user

    as well as in the wp_insert_post function (first function) after the line:

    extract($postarr);

    and one of these options worked. I also edited the first block to read as follows:

    $sql = “SELECT * FROM $wpdb->posts WHERE post_status IN (‘publish’, ‘draft’, ‘private’, ‘static’) ORDER BY post_status DESC, post_date DESC $limit”;

    This puts the *pages* at the top of the list in BlogsInHand, so they are always available for editing.

    I really didn’t know what I was doing, and am surprised this worked so well, but so far so good. Thanks for your great script! This perfected my pocket pc blogging experience.

  11. Pingback: loggedoff.org » Blog Archive » Using WordPress as a CMS

  12. There’s a pretty easy workaround with Ecto. Just make a post as normal, upload any pictures from the pic editing sheet, and then copy the html.
    You can then just paste it into a page.

    It’s quick enough, and you get all the custom html templates you may be using.

    I understand direct posting is easier, but for the amount of pages I actually creat or edit it’s quicker for me to do ti this way than to remember to re-hack all my php files with each WordPress update.

    Hope this helps!

    [tags]wordpress hacks ecto[/tags]

  13. Sadly, this appears to now be broken with the latest version(s) of WP (2.0.6) and/or Ecto (2.4.2). When I try to refresh the posts in Ecto, I get an error in the Console log complaining about the first block change (‘$sql = “SELECT…’).

    If anyone is able to find a workaround for this bugaboo, I’m definitely interested.

  14. Pingback: » WordPress 2.2 Out

  15. Pingback: Editing WordPress Pages with Ecto

  16. Pingback: Chukki.de - Der Wordpress Blog für Webdesigner & Webentwickler

  17. Pingback: Sameer Ahuja » Editing Wordpress pages using blogging tools

  18. Thanks dude that really helped me even if it’s not final in my eyes. I will try to advance your script to fit my needs but thanks for this “base” :-).

  19. Trying to figure out how to enable static post editing in the TextMate blogging plugin, but I’m not sure how recent WordPress updates have changed things. Also, as of ecto v3 you can edit wordpress pages without any mucking around, you just have to request them (ecto doesn’t automatically grab them).

  20. @Alex Yule: Thanks for the update. This post is from 2005, and I haven’t really followed up on it much since then (I’m pretty happy using the web-based editor now). Good luck with your quest.

  21. Does anyone know if there is another language or set of commands beside SQL for talking with databases?

    I’m working on a project and am doing some research thanks

Comments are closed.