User last login and user last visit problem

When you are using human_time_diff for convert time to human readable format. your last_visit meta empty that is why it is return 50 years. so before convert human_time_diff you have to check value is not empty. use below code to display last_login, last_visit. $users = get_users(); foreach( $users as $user ) { $udata = get_userdata( … Read more

set a user-meta key as avatar

<?php $id = get_current_user_id(); // this is for the current user, for other user just change this variable to the user id intended $link = get_user_meta( $id, ‘avatar’, true ); ?> <img src=”<?php echo $link ?>” alt=””> That is your answer, but if you want to understand it just continue reading!.. (only after writing everything … Read more

Incrementally add or substract from usermeta field

The function below should do your job. function manage_credits( $operation = ‘add’, $amount = 0 ) { $user_id = get_current_user_id(); if ( $user_id ) { $user_credit = (int) get_user_meta( $user_id, ‘my_user_credit’, true ); if ( ‘add’ == $operation ) { $user_credit += $amount; //For adding credits } elseif ( ‘remove’ == $operation && ( $user_credit … Read more

WP_user_query throws a 404 error

pre_user_query is called after the query variable object is created, but before the actual query is run. Your code is creating a new query within the action when you should actually modify the existing query’s arguments using the $query->set() method. For example: function my_pre_user_search($user_query) { $meta_query = array(array( ‘key’ => ‘member_id’, ‘value’ => ‘2349’ )); … Read more

update_user_meta() not working

wp_get_current_user() returns an object. update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ) accepts user_id as first parameter. Use the following code to get user ID from wp_get_current_user() update_user_meta( $user->ID, ‘custom_user_fields’, $userData );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)