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


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?

share|improve this question
Does your $wpdb->update() method work when you're not calling it via ajax? – sanchothefat Mar 6 '12 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 '12 at 10:26
up vote 2 down vote accepted

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() )
share|improve this answer

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.