1

Trying to save multiply checkboxes in a widget, but no luck. Here is my code:

function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['title'] = strip_tags( $new_instance['title'] );
        $instance['social_displays'] =  $new_instance['social_displays'];

        return $instance;
}

function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'social_displays' => '') );
$title = esc_attr( $instance['title'] );
$social_displays = array(
    'facebook_display' => array(
        'value' => 0,
        'label' => __( 'Facebook', 'higher' ),
    ),
'twitter_display' => array(
    'value' => 0,
    'label' => __( 'Twitter', 'higher' ),
),
);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'higher'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>

<label for="<?php echo $this->get_field_id('social_displays'); ?>"><?php _e('Which links would you like to display?', 'index'); ?></label><br />
<?php foreach ( $social_displays as $social_display ) { ?>
    <label class="description">
    <input name="<?php echo $this->get_field_name('social_displays'); ?>" type="checkbox" id="<?php echo $social_display; ?>" value="1" <?php checked(   $social_display['value'], 1 ); ?> />
    <?php echo $social_display['label']; ?>
    </label><br />
<?php
}
}

Any help, please?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.