Getting $_POST variables in a WordPress Plugin on save
I’ve been making more and more wordpress plugins lately and it seems to me that a vital part is getting certain variables back once a post is saved. I had a bit of trouble on this since the logical hook of save_post() was not returning my variables. After a lot of messing around I came to the conclusion that if you use the init() hook you can pull your variables and do whatever actions there, however keep in mind, on init() wordpress is not loaded so you can’t use wordpress functions.
Anyway here is an example…
function checkCheckBox() { global $_POST; if($_POST['checkbox'] == 1) { return true; // You would more likely set an option or define a constant here instead so it can be more global } return false; } add_action('init', 'checkCheckBox');
Hope this helps someone, I know it would have saved me alot of time if I knew.
























Craig M. Rosenblum said
am September 5 2009 @ 3:09 am
I am strugglign to do similar things, like grab $_POST data from user register/login…
But it seems impossible to grab that data as part of a plugin..
did you ever find a solution?
Andy said
am September 7 2009 @ 9:29 am
@Craig
At the moment you have to be handy in wordpress plugin creation. You can get the $_POST variables on the site initilization or init() hook. Other than that you might be out of luck for now. I would like to eventually make a plugin for this where you just put which $_POST variable you want into the page content and it will show. So keep your eyes open for that! Thanks, Andy
gulleydrorary said
am November 7 2009 @ 6:33 am
Is social media going to kill SEO?
Coattylot said
am November 14 2009 @ 5:08 am
I found this site using google.com And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!
Sorry for offtopic