List users by last name in WP_User_Query

There is a better way to do this as of WordPress version 3.7. Use the WordPress property meta_key to select the last name property and then orderby => meta_value with an ascending order. <?php $args = array( ‘meta_key’ => ‘last_name’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’ ); $user_query = new WP_User_Query( $args ); if ( … Read more

Is there a way to merge two users?

Generally speaking I agree with most of the other answers but, if for some reason you really had to merge two accounts here is how that could work. Merging User-B into User-A Reassign all of User-B’s content to User-A Determine the highest privilege of User-B If higher than the privileges of User-A elevate User-A’s privileges … Read more

How to get userid at wp_logout action hook?

How about hooking ‘clear_auth_cookie’ with the cleaning you need to do? If you need even more depth, you can outright replace wp_clear_auth_cookie(), but that can get into issues where it will conflict with other plugins, so avoid that if possible.

Commenting in user profile page?

Hi @Towfiq: Comments are related in the database to Posts. You’ll have to do a lot of work to get Comments to relate to Users. Have you considered creating a Custom Post Type for Users and then use either a user_meta field to store the post_id, or a postmeta field to store the user_id, or … Read more

How to bulk delete all users with no posts?

If you have a large number of users to delete, you might consder using the wp user delete wp-cli command to avoid script timeouts. Here’s an example of a SQL query to delete all users without posts of any type and status. You can therefore try this untested one-liner: wp user delete $(wp db query … Read more

get_current_user_id() returns 0?

Going by wp_get_current_user() information in the Codex, the function utilizes the global $current_user object and if necessary initializes it before use. As others have stated, get_current_user_id() uses this function on the backend. Consider /wp-includes/user.php, lines 323-327 (the function definition for this code). At the tail end, the return value is return ( isset( $user->ID ) … Read more

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