Ive got whole bunch of checkbox inputs which all have same name attribute. I want to save their values (1 if checked, also 0 if not because order matters, I need to output them in right order) as an array which is not going as expected.
<input type="checkbox" name="feature[]" id="feature-a"/>
<input type="checkbox" name="feature[]" id="feature-b"/>
<input type="checkbox" name="feature[]" id="feature-c"/>
<input type="checkbox" name="feature[]" id="feature-d"/>
etc
foreach( $_POST['feature'] as $feature ) {
if( isset( $feature ) && '' !== $feature ) {
$feature = 1;
}
else {
$feature = '';
}
$features = array();
array_push($features, $feature);
}
update_term_meta( $term_id, 'features', $features );
//This always outputs a:1 {i:0;i:1;} for some reason! No matter what I check
What am I missing?
- I tried to add
feature[]
as name attribute - I tried to assing '' or "" to
$feature
Nothing is working. Is there a mistake in my loop I can't see?