This probably isn’t the best way to proceed, but seeing as nobody else answered…
I recently was in the same situation, heres how I did it :
- Named the fields so I could access them as an array in the $_POST (ex. name=”description[]”), and gave new appended fields the same name.
- Using the ‘save_post’ hook, gathered the data in $_POST
- Deleted all previous entries for the custom field using ‘delete_post_meta‘
-
Did a For loop on either field and combined each pair into one post meta entry because I had pairing problems when adding them seperately, ex :
for( $i = 0; $i < count($names); $i++ ){ $meta = $names[$i] . "-=-" . $descriptions[$i]; //combine with a seperator add_post_meta( $post->ID, "name_description", $meta ); //Save custom field }
Then, when showing the values saved, simply split the field on the seperator you added, and add the paired values into their respective input field.
Of course, I validate the information first, and make sure there aren’t empty values and such, but that’s the gist of it.