0

i'm developing a small plugin which will send email to users when a new magazine is published.

i made a post type name "magazine" on the theme functions.php. and i wrote a plugin for email subscriptions.

code:

function newsletter_sendEmails($post_id)
{
    $post = get_post($post_id);

    if ($post->post_type == 'magazine')
    {
        mail( "[email protected]", "מגזין חדש", "התפרסם מגזין חדש!" );
    }
}

add_action('publish_post', 'newsletter_sendEmails');

but from some reason i don't get the email when i publish a new magazine, why is that?

1

1 Answer 1

3

It's never fired since the hook you need is not publish_post but publish_magazine which is actually {$new_status}_{$post_type} hook. So try publish_magazine

update: also you don't need to use get_post since you the hook passes the $post object to the function as a second parameter. take a look at wp_transition_post_status()

and if that's not working then you have something else going wrong.

1
  • doesn't work either :\
    – Dor Zuberi
    May 13, 2012 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.