• Hi, is there a way to execute a piece of code from a plugin only the very first time a post record is created?

    (corresponding to $update being TRUE in wp_insert_post() in function-post.php)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sam5n

    (@sam5n)

    OK, the following seems to work. Is this the right way of doing it?

    add_action(‘save_post’,’sd2_save_post’);
    function sd2_save_post($id){
    if($_POST[‘prev_status’] == ‘draft’){
    // this post is just being created

    Do you want it when it is PUBLISHED or when it is actually CREATED?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Run a piece of code only when a new post is created’ is closed to new replies.