Show WordPress users in grid with image and name

The first thing you have to do is create the shortcode you need: function wpusers_shortcode( $atts ) { // Attributes $atts = shortcode_atts( array( ‘group’ => ‘logistics’, ), $atts ); // code here } add_shortcode( ‘wpusers’, ‘wpusers_shortcode’ ); Now you have a self-closing shortcode. Now it’s time to consult the database to get all registered … Read more

Didn’t get array of users like in delete action WPList table in users tab

You’re handling the request incorrectly, load-users.php is not the correct hook Instead, use handle_bulk_actions-users add_filter( ‘handle_bulk_actions-users’, ‘sanzeeb_bulk_action_handler_user’, 10, 3 ); function sanzeeb_bulk_action_handler_user( $redirect, $action, $object_ids ) { // let’s remove query args first $redirect = remove_query_arg( array( ‘assign’ ), $redirect ); // do something for “Assign” bulk action if ( $doaction == ‘assign’ ) { … Read more

How to count total words for posts published by one author?

Here’s a basic concept how I’d do the word counting and showing the count. Hopefully this serves as a starting point. I think it would be a good idea to store the word count in a transient, so it isn’t calculated on each and every author archive page load. function author_word_count() { // get current … Read more

Allow admins to login as other users

You’ll need to find out what specific capabilities Admin users are missing. Once you know the full list, you can use add_cap() to add those capabilities to the Admin users and enable them to do whatever the other roles are doing. From Shold I manually add ‘cap’ to admin role ? – $role = get_role( … Read more

Add custom user meta data

Adding custom field to all existing users. You will have to get the list of users and then, in a loop, set a custom field for each of them. $users = get_users( [ ‘fields’ => ‘id’, ‘meta_key’ => ‘YOUR_META_KEY’, ‘meta_compare’ => ‘NOT EXISTS’ ] ); if ( is_array($users) && count($users) ) { $meta_value = false; … Read more

User roles not displaying

You can’t see any roles printed, because the ->roles field is an Array, so you can’t print it using echo. User print_r instead. You also have an error in this line: $user = get_userdata(userID); There is no such thing like userID – it should be $userID.

Get user by meta key – WP multi site

This is the problem: $user = reset( get_users( reset expects a reference to an array, and there’s no mechanism for error checking. So even if it finds the user, you’re misusing the return value. It might be possible to adjust this to use references properly, but references in PHP are something best avoided, and there … Read more

Order users by user role

@CynthiaLara I suppose that you are using a container of WP_USER_QUERY::__construct in the form or WP_USER_QUERY or get_users or something to that effect. You can use ‘meta_key’ => ‘<YOUR_DESIGNATION_META_KEY>’,’orderby’ => ‘meta_value_num, to get results sorted by your meta key’s value. If you have used a texted based value in for this meta_key, please consider using … Read more

Fix ‘Add Role’ Option not there in wordpress 5.2.2

“Add Role” isn’t an option in WordPress, and never has been. If you want to add a role you’ll need a plugin like User Role Editor or Members. If you want to add a role with code, you can do this with the add_role() function: add_role( ‘member’, ‘Member’, [ ‘edit_posts’ => true, ] ); Just … Read more

user_meta table in staging vs live site

Passwords are stored in users not usermeta. I’d copy both tables over and it’ll work fine. `wp_users` ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `user_login` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ”, `user_pass` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ”, `user_nicename` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ”, `user_email` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT … Read more

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