• Home
  • Docs
  • About
  • Resume
  • Services
    • Testimonials
  • Contact
Humbug
Bah! Humbug!
Home 2010 Redirect WordPress XMLRPC Clients to a Custom Post Type

Redirect WordPress XMLRPC Clients to a Custom Post Type

  • 13 Comments
  • Tweet
Pratik Sinha | July 10, 2010

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 :)

Posted in Tips-N-Tricks | Tagged android, custom post type, iphone, p2, wordpress, xmlrpc | 13 Responses

  • Tweet
Logging In...

Profile cancel

Sign in with Twitter Sign in with Facebook
or

Not published

 

  • 13 Replies
  • 13 Comments
  • 0 Tweets
  • 0 Facebook
  • 0 Pingbacks
Last reply was 41 days ago
  1. Varun
    View 676 days ago

    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.

    Reply
    • Pratik Sinhareplied:
      View 672 days ago

      You could also use this plugin. It lets you customize themes through the wp-admin. Even if the theme updates, your customizations will not be affected.

      Reply
  2. Pratik Sinha
    View 673 days ago

    @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.

    Reply
  3. Aaron D. Campbell
    View 573 days ago

    While the changes wouldn’t get overwritten, it only lets you use a custom post type at the expense of not being able to work with actual posts.

    Reply
    • Pratik Sinhareplied:
      View 569 days ago

      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 :)

      Reply
  4. Xander
    View 392 days ago

    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.

    Reply
    • Pratik Sinhareplied:
      View 376 days ago

      @Xander, the code snippet still works for me, not sure why it isn’t working for you.

      Reply
      • Xanderreplied:
        View 374 days ago

        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 ?

        Reply
        • Pratik Sinhareplied:
          View 372 days ago

          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;
          }
          
          Reply
          • Pratik Sinhareplied:
            View 372 days ago

            Ofcourse you gotta chage ‘custom_post_type’ to the post type you’re using.

          • TGreplied:
            View 311 days ago

            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

  5. Bibhas
    View 41 days ago

    Your code is broken.
    This line needs a semicolon in the end.
    $p2_custom_post_type = ‘custom_post_type’

    Reply
    • Pratik Sinhareplied:
      View 41 days ago

      Thanks for pointing that out, I have updated the post.

      Reply
« Previous Next »

Search

Recommend on Google
  • RSS
Follow @free_thinker

Get the latest posts delivered straight to your inbox.

Categories

  • Bookmarks
  • Code-Snippets
  • Guides
  • Info
  • Software
  • Testimonials
  • Tips-N-Tricks
  • Updates

Recently Popular

  • Make English the Default Language for Google Chrome Search
  • Parse Simple XML Files using Bash – Extract Name Value Pairs and Attributes
  • Kill/Quit and Restart Plasma on KDE
  • Bash Tricks: Split / Cut a String with Multi Character Delimiters
  • Enable SPDY in Firefox 11 on Ubuntu 12.04 beta
  • Utility to Send Commands or Data to Other Terminals (tty/pts)
  • A Sample Loop in XSL, Alternative for While, For Loops
  • Bash Tricks: Create variables dynamically using some eval magic
  • Kickstrap – CSS Framework: Enhancements for Bootstrap
  • WordPress Plugin: Cleaner WordPress Editor – Trying To Make WordPress Editing a Pleasure

Latest Tweets

  • 2 unexploded bombs found under Ho Chi Minh City house - Approximately 800,000 tons of bombs and mines still present humbug.in/z/9i #fb 4 weeks ago
  • 3 Vietnamese bloggers charged over their writing | Fox News humbug.in/z/9g #fb 1 month ago
  • Implement strong WiFi encryption the easy way with hostapd - Using WPA2-Personal with individual keys for each user humbug.in/z/9e 1 month ago
  • Soon, wonder vaccine that will kill 90% of cancers - Health - DNA humbug.in/z/9d 1 month ago
  • PHP like str_replace function in C: This post is part of a series of posts where I want to document a bunch of C f... humbug.in/z/9c 1 month ago

Services Offered

  • Embedded Linux Systems and Services
  • Gateway Routers (Frontend and Backend)
  • Free and Open Source Software Solutions
  • Network Monitoring Solutions
  • Device Driver Development


Mobile and Web Analytics

Recent Comments

  • Haakon Dahl commented on Make English the Default Language for Google Chrome Search
    (1 weeks ago)
  • pawan commented on Wordpress Error: The plugin generated 1 characters of unexpected output during activation
    (1 weeks ago)
  • simon commented on Detect Mobile Browser using Server Side Includes (SSI)
    (2 weeks ago)
  • hakatagroup commented on Twitter Weekly Updates between 2012-04-19 and 2012-04-25
    (3 weeks ago)

Tags

Address bar android awk bash C css custom post type debug Default Browser DNS dreamhost English Facebook firefox Google iphone JavaScript jquery KDE keyboard shortcuts Kubuntu Launchpad Linux Mozilla Firefox p2 page template pdf php plugin PPA python ruby ruby-on-rails Ruby1.9.2 Search Results SNMP theme tweets Twitter Ubuntu United States update-alternatives Vietnam wordpress xsl

Copyright © 2012 Humbug.

Powered by WordPress and Hybrid.