I have some specific functionality based on post's tags.

How can I send email to [email protected] when: 1) user add new post with specific tag (ex. 'tag1') OR 2) user edit his pending post and assign specific tag ('tag1')?

Thanks =)

2 Answers 2


Here is some simple code provided straight out of the WordPress codex. If you are not familiar with the Codex, you should make time to do so. https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

function my_project_updated_send_email( $post_id ) {

// If this is just a revision, don't send the email.
if ( wp_is_post_revision( $post_id ) )

// get the post data and check for tags here ...
$newpost = get_post( $post_id );
// Now you can do anything with the $newpost object you just created
// End of your custom code

$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';

$message = "A post has been updated on your website:\n\n";
$message .= $post_title . ": " . $post_url;

// Send email to admin.
wp_mail( '[email protected]', $subject, $message );
add_action( 'save_post', 'my_project_updated_send_email' );

I hope this helps.

  • The problem here is that if I add/modify only tags of the post - than wordpress does not add a new revision, so your code wont work.
    – user104980
    Oct 16, 2016 at 13:05
  • And it seems for me that revisions data does not include post's tag(s) information
    – user104980
    Oct 16, 2016 at 13:06

There are more action hooks related to saving and updating a post/page. So you may want to add_action for these as well and hook them to your function.

To get the tags when a post is saved, there is a section where I indicated you must put additional code. This would be something like a wp_get_post_tags( $post_id ) function call where you can then manipulate the data.


Again, you should reallu explore the codex as all of the action hooks and functions are explained there.

Your Answer

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