i finally found the answer, its actually not a problem with the code i posted. its in the update()
function. i have some validation code
function update($new_instance, $old_instance) {
$instance['title'] = esc_attr(strip_tags($new_instance['title']));
if (is_int($new_instance['number_products'])) {
if ($new_instance['number_products'] > 0)
$instance['number_products'] = $new_instance['number_products'];
else
$instance['number_products'] = 1;
} else {
$instance['number_products'] = $old_instance['number_product'];
}
return $instance;
}
the problem is at 2 places. i should be using is_numeric
over is_int
, the reason is
To test if a variable is a number or a
numeric string (such as form input,
which is always a string), you must
use is_numeric().
then, in the else, $old_instance['number_product']
should have be plural $old_instance['number_products']