Redirect WordPress XMLRPC Clients to a Custom Post Type

Lets say you want to post from your Android or Iphone WordPress clients to a custom post type instead of the the defualt ‘post’ type. Paste the code below in your functions.php and you should be good to go 🙂

function redirect_xmlrpc_to_custom_post_type ($data, $postarr) {
    $p2_custom_post_type = 'custom_post_type'; //Change this to the custom post type you are using for your blog
    if (defined('XMLRPC_REQUEST') || defined('APP_REQUEST')) {
        $data['post_type'] = $p2_custom_post_type;
        return $data;
    }
    return $data;
}

add_filter('wp_insert_post_data', 'redirect_xmlrpc_to_custom_post_type', 99, 2);

Change $p2_custom_post_type = 'custom_post_type' to the custom post type you are using for your blog.

Now I can post from my Android Phone to my custom P2 micro-blog 🙂

14 comments

  1. Hey, thanks form sharing 🙂
    Do you eventually have a solution to list this post-type in the app? This would be awesome! Best regards, Steffen

  2. The code doesnt work anymore.
    It gives me a 500 internal error message.
    Can you update this post? You are the only one on the web with this sollution. Too bad it is outdated.

      1. Don’t you have a idea how this might happen ? When I use the code snippet it gives me a 500 internal server error. I have xmlrpc enabled. Do I need to do something in htacces maybe ?

        1. Can you try this?

          function redirect_xmlrpc_to_custom_post_type ($data, $postarr) {
            if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) {
              $data['post_type'] = 'custom_post_type';
            }
            return $data;
          }
          
          1. No its same – I got the same problem. the method doesnt work if I put this in the functions.php.

            BTW I’m using WP 3.2.1

    1. True, and I use my desktop blogging application only for my custom post types. However it should be easy to modify it to lets say make it tag based. If you have a tag “custom_post_type” then it will publish as your custom post type or as a normal post otherwise. Your comment went into the spam folder for some reason, akismet doesn’t like you 🙂

  3. @Varun Well they won’t be because the theme for my website is a custom child theme for the hybrid wordpress theme. Infact I always run the svn trunk version of hybrid, so it updates almost every second week. Even the theme for the NSM Website is a child theme I adapted from a old theme by the same developer – Justin Tadlock.

  4. Cool! But is there a more maintainable way to do it? You custom changes will get wiped out in an automated upgrade and will need to be reapplied.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.