Support Forum

sph_post_create versus sph_after_post action

1
Mike Grace-Martin
Member
Mar 1, 2018 - 4:00 pm

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.

Mike Grace-Martin
Member
Mar 1, 2018 - 4:15 pm

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

Yellow Swordfish
Glinton, England
Member
Mar 1, 2018 - 4:18 pm

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,

Mike Grace-Martin
Member
Mar 1, 2018 - 7:36 pm

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.

Mr Papa
Simi Valley, CA
Member
Free Members
Mar 1, 2018 - 8:39 pm

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

1