Skip to content
Advertisement

wp_after_insert_post not triggering

I am trying to send an email after a new post has been created. It needs to be sent after the creation of the post, because I want to include the post category in the email. wp_after_insert_post does not seem to work, as no email is sent. I have tried using the same code with the publish_post hook instead, which does send an email correctly, but I am then unable to use the category name in the email.

JavaScript

Is there any solution for this? Thanks in advance

Advertisement

Answer

It’s possible your wp_mail() function syntax is incorrect, you also have an extra space in your add_action(). I’ve not seen documentation or examples where you can assign variables a value in the function itself. I would try either declaring your variables outside the function, like so:

JavaScript

Or just put the values directly in that don’t have declared vars for:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement