You are going in wrong direction there is no way to get user role while admin change from back end. You can retrieve the role object for the current user by calling get_role(), but that’s an object rather than a string with the role name.
function get_user_role($uid) {
global $wpdb;
$role = $wpdb->get_var("SELECT meta_value FROM {$wpdb->usermeta} WHERE meta_key = 'wp_capabilities' AND user_id = {$uid}");
if(!$role) return 'non-user';
$rarr = unserialize($role);
$roles = is_array($rarr) ? array_keys($rarr) : array('non-user');
return $roles[0];
}
Related Posts:
- How can I query all users who registered today?
- How to count get_users query?
- Export Specific User data without plugin
- Modify users.php query with multiple taxonomies
- WP_User_Query with more than two custom meta values
- Wpdb->last_query returns bad query
- WP_User_Query. Whats wrong with ‘relation’ => ‘OR’
- How to display SQL query that ran in query?
- Custom query_var causes displaying posts archive on front page
- What is the most efficient way of implementing a favorite post system?
- Why does get_the_time(‘F j’) return November 30 for all posts?
- Query by one meta_key and sort by another (possibly NULL value)
- Search Terms – Querying on either description__like OR name__like in the same Term Query?
- Query & Sort Comments by custom comment meta
- Count user posts by user ID, Post type and Post status
- is_archive() doesn’t work on public query var archive pages?
- How to get category link without a database query
- search through post-type attachments titles
- Possible to get posts from multiple meta keys/values in a single query?
- Most effective use of DB querys
- Difference between fragment caching and wp_cache
- How to display all posts with today’s same month and day only?
- Two differents queries in archive page
- Select Multiple meta_value from WP DB; Single Query
- Select User by Joining Multiple Meta Value Results
- Show featured image as background image from postQuery
- How to set back query var author_name after unset it?
- Using $wpdb->update but confused on the WHERE in and SET
- My SQL function to change user_name
- How select a specific query when setting offset?
- Get all user meta by meta key instead of ID
- How to retrieve elements from another table in a SQL query?
- WordPress Loop: List All Posts by a Category & Subcategory
- Order query by post meta value
- List all posts from past week grouped by sub-category
- Query Custom Post Type posts by Keyword/url slug
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Display posts with a start OR end date later than current date
- Order posts by custom field DATE value
- How to display user order by role
- sql select query in wordpress ‘page’ [closed]
- wpdb->term_taxonomy count posts from both published and private posts?
- Form redirect with query vars to page
- Query to Get All Users from wp_users With NO matching user_id In wp_usermeta
- Group custom post listing in admin section
- WordPress custom setting page – add flashing message
- Custom query AFTER rss fetch_feed not working
- Multiple Category Query
- list all categories that have a certain word in title
- Passing parameters to a static front page
- wp_list_pages() refuses to output posts
- Can’t seem to do combined query AND sort?
- sort query results by newest
- How to reset usual $query on search page to push custom $wpdb query there?
- get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)
- Order by meta value pro first then meta value free in my search function
- Order posts by date, but also give priority for a specific term
- How to delete all posts, categories and tags from WordPress database
- Ideas how to search & replace post_content when string contains a newline?
- Combine “Exclude” Query in functions.php
- Query the WordPress database to get data together with replaced information
- $wpdb->prepare affecting the query?
- WordPress SQL search, how to handle SQL Injection?
- prepare function sql safe method
- Query for Custom Post Type UI Does Not Loop All the Post
- Updating with $qpdb->query() always returns 0 rows affected
- Wrap/close ‘query’ for a first-letter ordered listing of posts
- wpdb query with dynamic column name?
- How to manage a particular “order by” for get_search_query()?
- Query to view scheduled or draft post
- How to add a Variable to post query
- get products by custom date variable
- Sort a list of a CPT ( job) if a meta is empty
- How to delete all images from code in all post_content
- How to sort by two meta keys in admin area?
- Restrict WordPress search to a single ACF field
- wp query multiple values > display a specific value first
- PHP Fatal error: Uncaught Error: Call to a member function insert() on null
- Nested select statements not working
- How to query users by post count no less than 10
- Restore WordPress Backup Locally?
- Trouble migrating custom post types from non-wordpress cms
- Pagination adds search query (again)
- “order” does not affect order of custom query
- Create a new post on a specified publish date via link?
- Exclude Posts from a Widget
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- Query String for the WP_QUERY parameters
- $wpdb query for price in custom field value
- Advanced Custom Fields Query with Different Values of the Same Key
- No results for taxonomy archive page
- Multiple terms not working on taxonomy
- Sorting of coupons in the right way
- excludeCat function reverses order of blog posts
- Run search query again without pagination gives no results?
- Filter the feed page post limit
- WP_Query orderby meta key/value suddely stopped working
- Where can I find the SQL to get the most used information by wordpress database?
- WooCommerce Total # orders [closed]
- How to figure out correct wp_options to have autoload=’yes’