WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] save_post and wp_insert_post don't pass $post argument (3 posts)

  1. tsimion
    Member
    Posted 3 years ago #

    Hi there,

    I'm working on a plugin with custom post_type.

    I've added a hook for the 'save_post' action so I can process the extra meta data required by my post_type:

    add_action('save_post', array('myObj', 'on_save_post'));

    and the function is:

    class myObj {
     function on_save_post($post_ID, $post)
     {
      // process here
     }
    }

    However, the second argument ($post) doesn't get passed when I 'Publish' the post.
    In fact I get a PHP Warning message:
    Warning: Missing argument 2 for myObj::on_save_post in <file> on line <line_no>

    the action call inside wp_insert_post() is
    do_action('save_post', $post_ID, $post);

    What am I doing wrong?

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    That's because your add_action call defaults to supporting one argument, update your add_action call to..

    add_action('save_post', array('myObj', 'on_save_post'), 10, 2 );

    http://codex.wordpress.org/Function_Reference/add_action

  3. tsimion
    Member
    Posted 3 years ago #

    Oh snap! Forgot about that.

    Thank you very much, Mark.

    Have a nice day!

Topic Closed

This topic has been closed to new replies.

About this Topic