I am trying to update my custom database table when changes are made in a dialog box. The script for the dialog box and ajax call is as follows -


$("td > span").click(function(){

    var id = $(this).attr('id');
    var message = "message"+id;
    var content = jQuery("#"+message).text();
    var $dialog = $("<div></div>").html("<textarea style='width:99%; height:90%' class='popup-content'>"+content+"</textarea>").dialog({
        height: 400,
        width: 400,
        title: 'My Data',
        modal: true,
        autoOpen: false,
        dialogClass: 'wp-dialog',
        buttons: {
            "Save": function(){
                    type: "post",
                    url: script_data.admin_ajax,
                    data: {
                        action: "feedmng_update",
                        feed_id: id

The above script works all well but for the Ajax part. The above code is a separate javascript file which I even enqueue in my php file. The following is the Ajax call related code to update database having the id passed during the Ajax call -

function __construct(){    
  add_action( 'wp_ajax_feedmng_update', array( &$this, 'feedmng_update' ) );
  add_action( 'init', array( &$this, 'feedmng_load_scripts' ) );

function feedmng_update(){

    global $wpdb;
    $feedid = $_REQUEST["feed_id"];
    $wpdb->update( $wpdb->feedmanager, array( 'message' => "New data" ), array( 'id',$feedid ) );

function feedmng_load_scripts(){

    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'jquery-ui-core' );
    wp_enqueue_script( 'jquery-ui-dialog' );
    wp_enqueue_style (  'wp-jquery-ui-dialog' );
    wp_register_script( 'feedmng-popup', WP_PLUGIN_URL.'/feed-manager/mypopup.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-dialog' ) );
    wp_enqueue_script( 'feedmng-popup' );
    wp_localize_script( 'feedmng-popup', 'script_data', array( 'admin_ajax' => admin_url( 'admin-ajax.php' ) ) );

EDIT Added the following to the script, console shows "Success"

success: function(){

My table name is wp_feedmanager and I am trying to update it's 'message' column. But it just wont update ? Any suggestions what should be done ?

For future reference -

The problem was here - The third parameter of update query should be array( 'id' => $feedid ) Also the EDIT regarding tablename suggested by Milo needs to be included !

  • You have a type in your $wpdn->feedmanager. It should be $wpdb->feedmanager.
    – josh
    Nov 10, 2013 at 15:55
  • Ok, I corrected that too...that aint a problem. Still not working. Nov 10, 2013 at 15:58
  • Are you receiving a success in your console when you run the ajax?
    – josh
    Nov 10, 2013 at 15:59
  • 1
    url: "admin-ajax.php" is almost certainly not the right path to admin-ajax.php
    – Milo
    Nov 10, 2013 at 16:03
  • @josh Receiving no success Nov 10, 2013 at 16:18

1 Answer 1


Assuming your javascript and ajax action code are otherwise correct, target admin-ajax.php with the correct path by localizing your enqueued script:

    array( 'admin_ajax' => admin_url( 'admin-ajax.php' ) )

Then in your javascript, reference that URL with:

url: script_data.admin_ajax


ah, missed this the first time: $wpdb->feedmanager isn't set unless you've explicitly set it somewhere. $wpdb->table_name only works for native tables, as those member vars are hard-coded directly into the wpdb class. change it to a string 'wp_feedmanager'.

also note that the wp_ table prefix can be (and should be) changed via wp-config.php, use $wpdb->prefix to make your code more portable:

$table_name = $wpdb->prefix . 'feedmanager';
  • Tried what you suggested...no success yet ! Nov 10, 2013 at 16:37
  • edit your question and add your current code, including your script enqueue code. use your browser's error console to check for errors and/or 404s.
    – Milo
    Nov 10, 2013 at 16:39
  • Added more relevant code Nov 10, 2013 at 17:47
  • see edit above.
    – Milo
    Nov 10, 2013 at 18:23
  • 1
    you'll have to do some more in-depth debugging then- hardcode an update that's not within an ajax request and get that working, echo every var at every stage to make sure it's what you expect, get a simple ajax request without the update code working, etc..
    – Milo
    Nov 10, 2013 at 18:41

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.