I figured I’ll leave the meta values saving on multiple fields in the db, because I’ve been doing allot of pre_get_post
query filtering. Some of the features in there are for searching/filtering on post meta data and would it start making things very difficult if I was to start saving values into doubly serialized values. A good habit to keep if I was to save just single, more simple, values in the near future.
To clear up some of the issues I had… I opted NOT to use update_post_meta()
when saving and just go with deleting all the values first and then adding them straight after. Checking the old value with then new one and then acting on it was getting too complex. Probably not the best practice.
if(isset($_POST[$field['id']])) {
$new = $_POST[$field['id']];
}
//Store repeater fields as one dimentional array with same key meta fields
if(is_array($new) && isset($new[0])){
//DELETE EVERYTHING FIRST
delete_post_meta($post_id, $field['id']);
foreach ($new as $key => $value) {
add_post_meta($post_id, $field['id'], $value);
}
}