WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From what I can tell the widget API is pretty straight forward and simple, yet for some reason my update code isn't taking effect properly. When I press [save] from the backend all fields are blanked, and nothing is actually saved.

When I drag my widget onto the sidebar region, an entry is created in the database for the widget.

1846, 0, 'widget_email-signup', 'a:2:{i:2;a:0:{}s:12:"_multiwidget";i:1;}', 'yes'

When I input values and save, none are saved. I've intercepted both $new_instance and $old_instance during the call to my update method and wrote their outputs to a file, but found nothing in them.

Full Code: http://pastebin.com/gtrfuciZ

Update Method

function update( $new_instance, $old_instance ) {
  $instance = $old_instance;

  $instance['title'] = $new_instance['title'];
  $instance['script'] = $new_instance['script'];

  file_put_contents( '/wp_results.txt', print_r( $old_instance, true ) );
  file_put_contents( '/wp_results.txt', print_r( $new_instance, true ), FILE_APPEND );

  return $instance; 

wp_results.txt (data found within update method)

    [title] => 
    [script] => 
( )
share|improve this question
up vote 3 down vote accepted

You're using get_field_id() for the name attribute of the form elements, but you should use get_field_name().

The field names are of the form widget-{$id_base}[{$number}][{$field_name}], but id's can't use [], so they are like widget-{$id_base}-{$number}-{$field_name}.

share|improve this answer
get_field_name for the field name. Example code is in codex: codex.wordpress.org/Widgets_API#Example – hakre Dec 29 '10 at 2:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.