WordPress – How to Post to Custom Post Type from IFTTT

if-this-then-thatWordpress

I recently discovered ifttt.com and have been working on creating a few IFTTT tasks for my Kansas City Royals website. I am in the process of adding the ability for fans to make quick posts, such as YouTube videos, links, photos, etc.

These FanPosts are each a custom post type. I would like to set up a few feeds to post automatically to the custom post type "FanPost".

I love that IFTTT can automatically post to WordPress, but I do not want to post simple video embeds, links and photos to the main articles (Posts) section of the website, instead, I want to post to the custom post type(s).

Best Answer

As the only way ifttt.com can post to Wordpress, is using the XML-RPC API, and that API currently doesn't support supplying custom post type while calling insert post methods(will support from 3.4), you can make use of the filter wp_insert_post_data. I accomplished that last month while building a hack. Here is a hack that would work the way you want, just add this to your functions.php file -

function redirect_xmlrpc_to_custom_post_type ($data, $postarr) {
    // This function detects a XML-RPC request and modifies it before posting

    $p2_custom_post_type = 'FanPost'; // Define your Custom post type

    if (defined('XMLRPC_REQUEST') || defined('APP_REQUEST')) {
        $data['post_type'] = $p2_custom_post_type; // sets the request post type to custom post type instead of the default 'Post'.
        return $data;
    }
    return $data;

}
// Add the filter
add_filter('wp_insert_post_data', 'redirect_xmlrpc_to_custom_post_type', 99, 2);

Remember, this filter will detect any insert post request via the XML-RPC API and insert them to FanPost type. Be it from ifttt.com or anywhere else.

Related Topic