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.

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];
        //print_r($saved);
        //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
add comment

2 Answers

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

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