WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
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

Your Answer


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.