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 made a plugin for some calculation.

Class Math {
var $id; // I want to map this id to post_id
var $a;
var $b;
var $c;

function calculate{
 $this->a = $value_from_post_meta_input_box;
 $this->b = $data_generated_in_calculating_process;
 $this->c = $result_of_some_function;
}
}

After activating the plugin, and setting up the post meta input box for $a, I am able to get $a saved in post meta. Now, how can I save $b and $c to post meta? How to say the current calculation is an instance of Math with current post_ID ?

share|improve this question
add comment

1 Answer 1

You can use update_post_meta() to save an array of values. It will be automatically serialized and unserialized.

update_post_meta($post_id, 'math', array($a, $b, $c));
share|improve this answer
    
The input box for $a is on the post-editing screen, the Math class is in a plugin. Where should I write down the update_post_meta code? if write in the Class, how it finds the $post_id? if write out of the Class, how it get the value of $b and $c? –  Jenny May 8 '11 at 7:39
1  
You should hook your save function to the save_post action, which takes the post ID as the first parameter. –  Geert May 8 '11 at 7:57
    
please show me how! Thanks! –  Jenny May 8 '11 at 8:09
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.