WordPress.org

Ready to get started?Download WordPress

Forums

Preventing Function Running at Post Preview (3 posts)

  1. toneburst
    Member
    Posted 3 years ago #

    I'm writing a function that runs when a post is saved in the Edit Post panel, hooked onto the save_post action hook.

    I'm having problems preventing the function running also when the Preview button is pressed. Can anyone tell me how to stop this happening? It doesn't need to run at this point (when it does, it breaks my plugin), as long as it does run when the update/publish button is pressed.

    Cheers,

    a|x

  2. toneburst
    Member
    Posted 3 years ago #

    OK, no idea if this is the correct way to do it, but I managed to find out that there's an item in the $_POST array that gets sent when the post is previewed that can be tested for, and can then end my save_post function early, before it screws up.

    So I basically added

    if( in_array( 'dopreview', $_POST ) )
    		return $post_id;

    at the start of my function.

    As I said, no no idea if this is the proper way (I suspect not), but it seems to work at the moment.

    a|x

  3. toneburst
    Member
    Posted 3 years ago #

    Can anyone tell me if the above is correct?

    Thanks,

    a|x

Topic Closed

This topic has been closed to new replies.

About this Topic