• Resolved acedanger49

    (@acedanger49)


    I am developing a new plugin. My plugin is performaing an action on a post as it is published to the blog so I have this function call: add_action('publish_post', 'send_email');

    For some reason, I don’t have the post ID when I am trying to get some information about the post. What variable should I be checking for? Currently, I am checking for $post_id but it is not coming over. I have deactivated all other plugins on this particular blog so no other plugins should be interfering with (or not returning) the post id.

    Thanks for any help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    ww.wp.xz.cn Admin

    The publish_post action explicitly sends you the post ID as the argument. Take a look at the relevant do_action call in functions-post.php.

    So, you just make your function look like this:
    function send_email($post_id = 0) {
    ...
    }

    Then do your add_action, same as you did above. The $post_id will get filled in for you. If it doesn’t, it’ll be zero, and you can check for that to be sure.

    Thread Starter acedanger49

    (@acedanger49)

    Thanks Otto, I don’t know how I missed that in the documentation.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘developing a plugin, how do I know the post id?’ is closed to new replies.