0

I have the following array:

$instance_defaults = array(
    'title' => 'Popular Posts',
    'num_posts' => $instance['num_posts']
);

I got the notice that num_posts is undefinded index. Tried to use array_key_exist, but didn't succeed any ideas how to remove the notice ?

public function form( $instance ) {
        $instance_defaults = array(
            'title' => 'Popular Posts',
            'num_posts' => $instance['num_posts']
        );

        $instance = wp_parse_args( $instance, $instance_defaults );
        $num_posts = esc_attr( $instance['num_posts'] );
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('num_posts'); ?>">
                <?php _e( "Number of posts to show: ", 'dx-posts-widgets'); ?>
            </label>
            <input class="widefat"
                   id="<?php echo $this->get_field_id('num_posts'); ?>"
                   name="<?php echo $this->get_field_name('num_posts'); ?>"
                   type="text" value="<?php echo $num_posts; ?>" />
        </p>
        <?php
    }
Rumen Panchev
  • 468
  • 11
  • 26

0 Answers0