Forums

[resolved] developing a plugin, how do I know the post id? (3 posts)

  1. acedanger49
    Member
    Posted 5 years ago #

    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.

  2. Otto
    Tech Ninja
    Posted 5 years ago #

    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.

  3. acedanger49
    Member
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic