Getting $_POST variables in a WordPress Plugin on save

June 24, 2009

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.

Stay in Touch!

Subscribe to our newsletter.

Solutions Architecture

browse through our blog articles

Blog Archive