• Hi there,
    I want to auto publish all articles of my WP blog on Facebook without using any plugin.

    I wrote some code, and it works… but now I need to invoke this code only when I publish a new article (not for revisions or autosave).

    That’s the code structure:

    add_action( 'save_post', 'koolmind_facebook_post_article',3 );
    
    function koolmind_facebook_post_article( $post_id ) {
    
         /* configuration of facebook params */
         ....
         ....
         /* end config */
    
        if ( !wp_is_post_revision( $post_id ) && !wp_is_post_autosave( $post_id ) ) {
    
        /* retrieve some data to publish */
    
        /* invoke my code to publish on facebook */
       }
    }

    Problem is that my code is invoked as soon as I click on “add new article”, and an empty draft is sent to my Facebook page. Then, as soon as I insert a single char on my article body, autosave is triggered and a new post is sent again to facebook.

    How can I avoid this behaviour? I need to call FB code only clicking on PUBLISH button.

    Is that possibile?? I’m sure it is!

    thanks

Viewing 1 replies (of 1 total)
  • Thread Starter koolmind

    (@koolmind)

    Hi everybody,

    somebody told me to try a different way, using one of these two methods:

    1. use ‘publish_post’ hook instead of ‘save_post’.

    add_action ('publish_post', myfunction) or
    add_filter ('publish_post', myfunction)

    leads to the same situation: nothing is published on facebook

    2. using these threee hooks together

    add_action('pending_to_publish', myfunction);
    add_action('draft_to_publish', myfunction);
    add_action('new_to_publish', myfunction);

    leads again to the situation of point #1

    any clever idea?

Viewing 1 replies (of 1 total)
  • The topic ‘wp_is_post_autosave does not work’ is closed to new replies.