Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
sph_post_create versus sph_after_post action
Avatar
Mike Grace-Martin
Member
Pro Subscribers
sp_UserOfflineSmall Offline
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.

Avatar
Mike Grace-Martin
Member
Pro Subscribers
sp_UserOfflineSmall Offline
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.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
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,

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mike Grace-Martin
Member
Pro Subscribers
sp_UserOfflineSmall Offline
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.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Mar 1, 2018 - 8:39 pm

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

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 616
Members: 17344
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10117
Posts: 79600