Quantcast
Channel: Question and Answer » wpdb
Viewing all articles
Browse latest Browse all 44

WPDB – Read and write value from / to database

$
0
0

I have a custom field in usermeta called vatnumber.
If the field has a value, how do I read that specific value for user X?

Here’s what I have so far:

<tr class="vatnumber">
    <th><?php _e( 'VAT-Number:', 'wpdb_usermeta' ); ?></th>
    <td><?php $wpdb->get_results("SELECT userid, vatnumber FROM usermeta"); ?></td>
</tr>

But I don’t quite understand wpdb yet.
I know it is used for reading and writing from and to the database, but if I need a value for a specific user, do I have to assign the user_id to a variable?

On the same side, how do I make sure a certain field writes into the correct place in the database?

I would be glad if you could give me an example code tidbit.

edit01:

from what I understand, I can change it to

<?php $wpdb->get_user_meta($user_id, vatnumber,"); ?>

But does $single = false give me an array for all users with their respective user_ids? Because user_id in this case is a variable.

I’m sorry that I haven’t used the WordPress database in a while, but how do I tell the system which user to get the info from? I would need to read the current_user ID, wouldn’t I?


Viewing all articles
Browse latest Browse all 44

Trending Articles