This may not exactly answer the question, but let’s see the issues with your code:
-
If you want to save the data in the same format as the default value (
$fields_default), then:-
Start your
foreachlike so:foreach ( $orderdescider as $i => $item ). -
Then inside that
foreach,$idand$checkboxshould always be set and defined like so:$id = isset( $item['id'] ) ? $item['id'] : ''; $checkbox_check = isset( $item['checkbox_check'] ) ? $item['checkbox_check'] : ''; -
And use the appropriate value in the field’s
name:<input type="hidden" name="orderdescider[<?php echo $i; ?>][id]" value="<?php echo $id; ?>"> <input type="checkbox" name="orderdescider[<?php echo $i; ?>][checkbox_check]" value="1" ...>
-
-
For the
checkboxfields, you can use this format when writing the markup:<input type="checkbox" value="{value}"<?php // wrapped for clarity checked( '{value}', '{current/saved value}' ) ?> ...>so in your case, it would look like this:
<input type="checkbox" name="orderdescider[<?php echo $i; ?>][checkbox_check]" value="1"<?php checked( '1', $checkbox_check ) ?> ...>where
1is the{value}, and$checkbox_checkis the{current/saved value}.(See the reference for more details about using the
checked()function.)
Hope that helps, and here’s the full foreach code I used for testing: (I omitted the field’s id, but make sure to use unique values)
foreach ($orderdescider as $i => $item) {
$id = isset( $item['id'] ) ? $item['id'] : '';
$checkbox_check = isset( $item['checkbox_check'] ) ? $item['checkbox_check'] : '';
?>
<li class="sortable-item flexit">
<div class="form-check">
<input type="hidden" name="orderdescider[<?php echo $i; ?>][id]"
value="<?php echo $id; ?>">
<input type="checkbox" name="orderdescider[<?php echo $i; ?>][checkbox_check]"
value="1"<?php checked( '1', $checkbox_check ) ?> class="form-check-input">
</div>
</li>
<?php
}