438 posts
  • Has been part of the Envato Community for over 3 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market

Hi, everyone! 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 ) {
$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 />

Any help, please?

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes