unofficially
Veteran
Friendly Neighbour
Member Likes (0)
Ok, so I'm making a custom function to post data to a custom table (within the WP DB) on submitting from the post screen. Got it working using a custom meta box and add_action('save_post') but for some reason the table is being populated twice with the same data.
Can anyone suggest the correct way to achieve it? Is there a standard procedure to save data to a custom table (i.e. not wp_postmeta, etc)
Thx

Responses (5)
Support Kangaroo (joined March 2011) Likes (0)
Greetings unofficially,
What happens when you do not include the add_action('save_post')? Does it still not post when you use the regular save post method i.e. save draft or publish?
Please advise.
Cheers, Joe
Member (joined September 2011) Likes (0)
Hi Joe, thx for the reply.
I followed your suggestion without success - but after spending a few more hours scratching my head I found it. Simple mistake, I had a check for admin before instantiating the class which wasn't bracketed so the class was being instantiated twice!! My bad! But your reply got me working on it again, so many thanks for your input :)
Cheers
Tony
Support Kangaroo (joined March 2011) Likes (0)
Greetings Tony,
Thank you for your reply letting us know, it can happen to anybody :-)
Thank you for being a WPMU Dev Member!
Cheers, Joe
Member (joined September 2011) Likes (0)
Just an update: the problem was still there! Looked a bit harder and I think I have solved it - according to the Action Reference:
It would appear that my class (including the db insert) is running multiple times possibly due to the autosave triggering it, then 'publishing' it also triggers it?! Not sure.
Anyway changing the add_action to:
appears to work!
Will test more and report back if necessary :)
Support Kangaroo (joined March 2011) Likes (0)
Greetings Tony,
Thank you for that update it is greatly appreciated.
Please let us know if you come across further difficulties concerning this intriguing issue.
Cheers, Joe
Become a member