• Hi, I’m the creator of the wordpress timebank plugin and I have a problem with the ‘first time insert’ of data on one table:
    I need to set only ONCE (and never again) the configuration table. (It has ID = 1 and there are no more rows)

    When disabling the plugin on the wordpress backend, and enabling it again I get a [Duplicate entry] error message. (It seems that WP is trying to set again the data that exists on the table).
    Is it posible to first check if the record i’m trying to create it’s set?

    Something like wpdb->insert_once(xxx)

    Thank you!

    Here the function on the install.php file:

    function jal_install_data() {
    global $wpdb;

    // INSERT CONFIGURATION
    $id = “1”;
    $default_anonymous = “(deleted user)”;
    $default_min_limit = “120”;
    $default_max_limit = “180”;

    $table_name = $wpdb->prefix . “tbank_conf”;
    $rows_affected = $wpdb->insert( $table_name, array( ‘id’ => $id, ‘default_anonymous’ => $default_anonymous, ‘default_min_limit’ => $default_min_limit, ‘default_max_limit’ => $default_max_limit );
    }

  • The topic ‘Is there a wpdb->insert_once ?’ is closed to new replies.