• I’m new to WordPress and I’m not a developer. I’m running an IFTT applet that posts a WordPress post each time I upload or like a video on Youtube.

    There is a bug with IFTT. It often posts the same post 2 or 3 times.

    Therefore, I’d like to avoid duplicates before they are published. I read on forums that I needed to add a XML RPC plugin.

    I tried this solution from WordPress StackExchange.

    <?php
    /**
     * Plugin Name: Avoid XML-RPC Post Title Duplication
     * Description: Prevent duplicate posts when doing wp.newPost via XML-RPC
     * Plugin URI:  https://wordpress.stackexchange.com/a/157261/26350
     */
    
    add_action ('xmlrpc_call', 'wpse_xmlrpc_call' );  /////
    
    function wpse_xmlrpc_call( $method )
    {
        if( 'wp.newPost' === $method )
            add_filter( 'xmlrpc_wp_insert_post_data', 'wpse_xmlrpc_wp_insert_post_data' );
    }////
    
    function wpse_xmlrpc_wp_insert_post_data( $post_data )
    {
        // Check if the post title exists:
        $tmp = get_page_by_title( 
            $post_data['post_title'], 
            OBJECT, 
            $post_data['post_type'] 
        );
    
        // Go from 'insert' to 'update' mode within wp_insert_post():
        if( is_object ( $tmp ) )
            $post_data['ID'] = $tmp->ID; 
    
        return $post_data;  
    }

    I added the code using Insert PHP Code Snippet WordPress plugin.

    But it doesn’t work for me. I still have duplicate posts coming in.

    I also tried to create a plugin file and it doesn’t work either.

    Is this code working?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s probably out of scope for the snippet plugin. That code is a plugin file of its own. Place it in its own file and upload to /wp-content/plugins/. Activate the plugin and see if that works for you.

    Thread Starter sylvainn

    (@sylvainn)

    I tried it already on its own file. It didn’t work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Avoid IFTT duplicate posts with XML RPC’ is closed to new replies.