Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My brain has fallen over. How do I save this post data? Building some key-value pairs in the form.

    for ($i = 1; $i <= 3; $i++) {
        $saved = $meta[$i];
        //echo $saved['key'];
        echo '<p>';
        echo '<label for="meta_k_'.$i.'">Key</label> ',   '<input id="meta_k_'.$i.'" type="text" name="_meta['.$i.'][key]" value="'.$saved['key'].'" />&nbsp;&nbsp;';
        echo '<label for="meta_v_'.$i.'">Value</label> ', '<input id="meta_v_'.$i.'" type="text" name="_meta['.$i.'][value]" value="'.$saved['value'].'" />';
        echo '</p>';

How do I save them???

    foreach ($_POST['_meta'] as $key => $value) {
        update_post_meta($post_id, $key, $value);
share|improve this question

2 Answers 2

up vote 1 down vote accepted

This should be work:

foreach ($_POST['_meta'] as $value) {
    update_post_meta($post_id, $value['key'], $value['value']);
share|improve this answer
Thanks! Just couldn't see it :-) – Niels Jun 29 '12 at 8:16

you are almost there. just hook your saving logic to 'save_post'.

add_action('save_post', 'custommeta');
function custommeta($post_id)
  //put your update code here
share|improve this answer

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.