Multidimensional array in widget
-
Hi there,
I am wondering if it is possible to create, save to, and use data from a multidimensional array in WP_Widget::form. My idea is to have multiple text fields accompanied with a weight (number) field. The order of the text field output will be determined using the numbers in the weight field.
Was hoping something along these lines would work:
$i = 0; foreach ($field as $name): $i++; $name = ltrim($name, '_'); ?> <li> <label> <?php echo $name; ?> <input type="checkbox" id="<?php echo $name; ?>" value="<?php echo $name; ?>" name="<?php echo $this->get_field_name('fields'); ?>[]" <?php checked(is_array($instance['fields'][$i]['field']) && in_array($name, $instance['fields'][$i]['field'])); ?> /> <input class="widefat" id="<?php echo $name; ?>-weight" name="<?php echo $this->get_field_name('fields'); ?>[]" type="text" value="<?php echo sanitize_html_class($instance['fields'][$i]['weight']); ?>"/> </label> </li> <?php endforeach; ?>but I haven’t had any luck with saving/output. Let me know if this is something that’s possible, or if more detail is needed. Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Multidimensional array in widget’ is closed to new replies.