Update some database fields when post is saved

Best way for storing them is WordPress’ Options Mechanism.

ANd best way to trigger it when a post saved is using WordPress save_post action.

Example :

add_action( 'save_post', 'count' ); //Execute count() when a post saved/updated
function count()
{
    your codes here ...

    //save them to DB
    update_option("lines-of-code", $lines);
    update_option("disk-space", $diskspace);
    ...
}

Leave a Comment