Support Forum

sph_post_create versus sph_after_post action

MM Mike Grace-Martin
Mike Grace-Martin
Member

I want to trigger my own custom function (that includes sending an email message) after someone posts in the forum. When I use the “sph_post_create” action as a trigger, I get one email message (like I want to), but the $spVars variable doesn’t contain the data about the post that I want. If I use the sph_after_post action, $spVars contains the data I want about the post, but then my function triggers multiple times for some reason, which I don’t want. Any idea how I can get the $spVars data I want but only have it triggered once? Thanks.

4 Answers

New Answer

MM Mike Grace-Martin
Mike Grace-Martin
Member

I also tried the sph_new_forum_post action, and $spVars again didn’t contain the post’s data.

YS Yellow Swordfish
Yellow Swordfish
Member

I would recommend the ‘sph_new_post’ action which has one argument which is the $newpost array which should have everything you need defined. And this is triggered at the post creation time after success of saving has been accomplished,

MM Mike Grace-Martin
Mike Grace-Martin
Member

It took me a while to figure out how to be able to use $newpost. It turns out I had to add two more arguments (the 10 & 1) in my add_action declaration: add_action( ‘sph_new_post’, ‘my_function’, 10, 1 ) …where the 1 refers to the one argument being passed to my_function via my_function($newpost). Thanks.

MP Mr Papa
Mr Papa
Member

yes, standard wp hook format…  glad we could help…