In my theme there is a notification at top. After user login he can see the notification update. when click on notification i want to make change in database alert field value 0 to 1.

My ajax call in theme

 $("#notifications-button").click(function() {

        type : 'POST',
        url: "http://localhost/rupp/wp-admin/admin-ajax.php",
        success : function(data){



and in function.php file

function MyAjaxFunction()
    global $wpdb;
  echo (int)$user_ID;
  $wpdb->update( $wpdb->wp_frm_items, 
            array( 'alerts' =>  1)

but it not make any changes in alert fields in db. is that right way to call theme function using ajax?

  • Does your $wpdb->update() method work when you're not calling it via ajax? Mar 6, 2012 at 10:22
  • No that is the issue .. i tried with just echo also but its not replaying me anything in consol
    – Ajay Patel
    Mar 6, 2012 at 10:26

1 Answer 1


You need to add the $where parameter to your update statement because it doesn't know which row to update. The $wpdb->update() method has no default value for the $where argument so you must supply one.


Try this:

$wpdb->update( $wpdb->wp_frm_items, 
        array( 'alerts' =>  1),
        array( 'user' => get_current_user_id() )

Your Answer

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

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