Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

all

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() {

        $.ajax({
        type : 'POST',
        url: "http://localhost/rupp/wp-admin/admin-ajax.php",
        data:{action:'MyAjaxFunction'},
        success : function(data){
            $('.message-count').hide();
        },

        });


});

and in function.php file

add_action('wp_ajax_MyAjaxFunction','MyAjaxFunction');
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

1 Answer 1

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.

http://codex.wordpress.org/Class_Reference/wpdb#UPDATE_rows

Try this:

$wpdb->update( $wpdb->wp_frm_items, 
        array( 'alerts' =>  1),
        array( 'user' => get_current_user_id() )
        );
share|improve this answer

Your Answer

 
discard

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.