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.

I have a class that will count the Lines of Code, Source Lines of Code, and the Code disk space used. I would like to save these values into the database so that these values can be calculated only when a new post is saved or updated instead of running the code on every page view

So my question is, what is the best way to make sure these are added/updated everytime a new post is made and everytime that post is updated/edited.

Also where should I store these, in a custom meta field? If so, how can I make sure that the meta box does not show up on the page, it should all be done behind the scenes

share|improve this question
    
Def: Meta Data. –  kaiser Dec 14 '11 at 0:08
1  
TIP: If you use a meta_key starting with an underscore it will be hidden from view(that's how core does it). –  t31os Dec 14 '11 at 0:49
    
Thanks for the tip! –  jasondavis Dec 14 '11 at 1:01
add comment

1 Answer

up vote 1 down vote accepted

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);
    ...
}
share|improve this answer
    
I need this saved for every post though so the options thing wouldn't work as it is for saving 1 key/value for the site and not 1 for each post. You save_post action will be useful though –  jasondavis Apr 11 '12 at 9:45
add comment

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.