On the back-end, you’re retrieving the data like this:
$meta = $_POST['attachments'][ $post_id ]['photo_time'];
$meta_two = $_POST['attachments'][$post_id]['photo_order'];
So on the front-end, you should set the field’s name
in this format: attachments[<?= $vP ?>][KEY]
where KEY
could be either photo_order
or photo_time
.
echo '<input type="hidden" name="attachments[<?= $vP ?>][photo_order]" class="photo_order" value="'.$Por.'" />';
echo '<input type="text" name="attachments[<?= $vP ?>][photo_time]" class="photo_time" value="'.$Pt.'"/>';
UPDATE
Saving the data:
Check the code in the UPDATE #2 section below.
Use that code in place of what you have (tried) — the code after this in your question:
When the form is submitted I am trying to save it using the following
(I commented out failed attempts) –
UPDATE #2
It’s probably preferred to wrap the code (for saving the data) in a function, like this:
add_action( 'init', 'my_save_vid_pix_data' );
function my_save_vid_pix_data() {
if ( ! isset( $_POST['attachments'], $_POST['v_Id'] ) ) {
return;
}
$atts = (array) $_POST['attachments'];
$post_id = absint( $_POST['v_Id'] );
$vid_pix = get_post_meta($post_id, 'vid_pix', false);
foreach ((array) $vid_pix as $vP) {
if ( ! isset( $atts[ $vP ] ) || ! is_array( $atts[ $vP ] ) ) {
continue;
}
update_post_meta($vP, 'photo_time', $atts[ $vP ]['photo_time']);
update_post_meta($vP, 'photo_order', $atts[ $vP ]['photo_order']);
}
}
(Add that function to the theme’s functions.php
file.)
And add a hidden input
field (named v_Id
) after this foreach
loop:
if (!empty($vid_pix)) {
foreach ($vid_pix as $vP) {
...
echo '<input type="text" name="attachments[<?= $vP ?>][photo_time]" class="photo_time" value="'.$Pt.'"/>';
}
echo '<input type="hidden" name="v_Id" value="' . $v_Id . '">';
}
(Please refer to your question for the $v_Id
variable.)