Basicly i want to check if a row exist in the metadata in wordpress. If the metakey table for that user does not exist it should make one.
This code i am using right now and it works but it seems buggy. I have recently notice that some users have two to five meta_key called credits now with value 0. Is there a better way to check if a meta_key already exist for the user or not?
This code i am using right now and it works but it seems buggy. I have recently notice that some users have two to five meta_key called credits now with value 0. Is there a better way to check if a meta_key already exist for the user or not?
Code:
<?php
global $current_user;
global $wpdb;
$useridvip=$current_user->ID;
$credits=$current_user->credits;
if (empty($credits)) {
$wpdb->insert( "wp_usermeta", array( 'umeta_id' => null, 'user_id' => $useridvip, 'meta_key' => credits, 'meta_value' => 0 ) );
$credits="0";
}
else { echo "all good"; }