0

I have created new columns in a SQL table called wp_users. Those fields are "giodo", "handel" and "regulamin".

What I want to do is to add '1' to each column when a user registers and selects corresponding checkboxes.

I added checkboxes to the form using form_register and then I added those checkboxes to user data with this (here is an example for only one of them):

add_action('user_register', 'myplugin_user_register');
function myplugin_user_register ($user_id) {
    if ( isset( $_POST['giodo'] ) )
        update_user_meta($user_id, 'giodo', $_POST['giodo']);
}

Can I somehow add their values to the database?

1 Answer 1

0

I have created new colums in a SQL table 'wp_users'. Those fields are "giodo", "handel" and "regulamin".

Don't add columns to Core tables. There is no guarantee that these won't be destroyed or corrupted on next update. What you should be using is user meta, and in fact that appears to be what you are actually using:

add_action('user_register', 'myplugin_user_register');
function myplugin_user_register ($user_id) {
        if ( isset( $_POST['giodo'] ) )
        update_user_meta($user_id, 'giodo', $_POST['giodo']);
}

So the question is a bit confusing.

Your code should have already inserted data into the database, just not where you are trying to put it. Your code should have inserted the data into the $wpdb->usermeta table and can be retrieved using get_user_meta(). That is what I would suggest. Abandon the attempt to add columns to a Core table and use the user meta API, which is what it was built for.

5
  • Thank you for your answer, but I find it hard seeing which meta piece is which. I used two foreach statements to echo out this data and there are no labels alongside those echoed pieces. Could you tell me how to make a distinction between them? Is there a function to put labels on this echoed meta data?
    – NakedCat
    Mar 20, 2014 at 14:46
  • You are doing something wrong. get_user_meta() without a specified key will give you an associative array. With a key... well, you already know what the key is.
    – s_ha_dum
    Mar 20, 2014 at 14:52
  • (Sorry for the formatting, I don't know how to change it in the comments) Hmmm I did this: $current_user = wp_get_current_user(); $arrays_globusy = get_user_meta($current_user->id); $x = 0; foreach ($arrays_globusy as $key => $value) { echo $key.": ".$value." <br>"; } and this is what I got: first_name: Array last_name: Array nickname: Array description: Array rich_editing: Array comment_shortcuts: Array admin_color: Array use_ssl: Array show_admin_bar_front: Array wp_capabilities: Array wp_user_level: Array
    – NakedCat
    Mar 20, 2014 at 15:03
  • var_dump($arrays_globusy); and spend a few minutes reading this: docs.php.net/manual/en/language.types.array.php
    – s_ha_dum
    Mar 20, 2014 at 15:04
  • Okay I will commit myself to it :). Thank you for yuour help.
    – NakedCat
    Mar 20, 2014 at 15:06

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.