Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Probably quite a simple problem.. I have a custom post type with taxonomy terms. I wish to run a function from my functions.php whenever the admin ticks a specific term box.

My original thought was to use add_action along with a "save_post" action so when the post is saved, it would loop through my terms and if the desired one is selected, it would run the function.

This is all good, except each time the admin updates the post it would run the function. The function is sends an email to a user, and I onyl want this email sent out ONCE. Is there any way I can set it so once the function runs it will not run again? I thought about updating a row in the DB and adding a "1" for example when the function runs, and having an if(){} within the fucntion to check if it had been ran before, but this seems like a dodgy way of doing it :/

Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

In your emailfunction, check if the date is difrent from the publish date, if so, don't email. This will cause you to email only once?

share|improve this answer
    
Yeah that would be good but the admin changing the term might change it days or weeks aftert the post was published... only need the email sending once, and only when the admin saves thwe post with a certain term ticked... thanks though :) –  JamesG Aug 21 '12 at 16:19
    
then your only option would be like you suggest yourself is to keep a value in your database, to check if it was already sent or not. –  woony Aug 22 '12 at 8:48
    
Ok thanks :) just wanted to see if tjhere was a more.. widely used and accepted way. –  JamesG Aug 22 '12 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.