get_users() ORDER BY Not Working

Try putting the args into an array. $args = array( ‘role’ => ‘subscriber’, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘fields’ => ‘all_with_meta’, ‘meta_query’ => $meta_query ); $my_users = get_users( $args );

WP_User->add_role producing unexpected results

This would be best as a comment, but no reputation 🙂 In the codex they say “If you are defining a custom role, and adding capabilities to the role using add_role(), be aware that modifying the capabilities array and re-executing add_role() will not necessarily update the role with the new capabilities list. The add_role() function … Read more

Is it possible to duplicate users on a new WordPress install?

Migrate DB Pro can help with this, make sure to migrate any plugin tables and the WP_Users and WP_Usermeta tables if your users make posts and you want that content to remain assigned an available make sure to keep WP_Posts and WP_Postmeta table as well. https://deliciousbrains.com/wp-migrate-db-pro/ Also keep in mind that WP uses an EAV … Read more

Drop down list in user profile page

thanks for that. Just one minor tweak, as the first bit of code threw up an error. Below is the working code for the first block of code. //hooks add_action( ‘show_user_profile’, ‘Add_user_fields’ ); add_action( ‘edit_user_profile’, ‘Add_user_fields’ ); function Add_user_fields( $user ) { ?> <h3>Extra fields</h3> <table class=”form-table”> <tr> <th><label for=”text”>text</label></th> <td> <?php // get test … Read more

set_role has no effect

You can use wp_update_user to update the role for your newly created user. if ( !username_exists( ‘mytestuser’ ) ) { $user_id = wp_create_user(‘mytestuser’, ‘testpass345′,’[email protected]’); $user_id = wp_update_user( array( ‘ID’ => $user_id, ‘role’ => ‘author’ ) ); } Further reading at WordPress Codex. Or, you can remove the current role and assign a new one: if … Read more

Update user_login to change username

First: The $wpdb object has the names of tables, with prefixes, pre-defined for you. $wpdb->users == ‘wp_users’ $wpdb->posts == ‘wp_posts’ etc. Second: $wpdb-prepare() is essentially a WordPress aware printf, if you pass it more than one argument, you need to have some string/digit replacements %s %d $sql = “UPDATE {$wpdb->users} SET user_login = %s WHERE … Read more