Display WP Users in Table format filter by Role

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
Hello all, I need help on display Users List on my Page in Table format filter by Role.

Currently I'm using Ultimate Members and it's Member Directory feature only show users in individual Card format. Unable to make it to show in Table format.

Respected expert here please advise, which Plugin or Shortcode I can use to achieve what I need? Please advice, thank you.
 
Last edited:

SharkTanker

Tech Guru
Trusted Uploader
Oct 30, 2018
388
648
93
corporatehitech.com.au
Hello all, I need help on display Users List on my Page in Table format filter by Role.

Currently I'm using Ultimate Members and it's Member Directory feature only show users in individual Card format. Unable to make it to show in Table format.

Respected expert here please advise, which Plugin or Shortcode I can use to achieve what I need? Please advice, thank you.
Hi mate
  1. Navigate to your CPanel
  2. Navigate to PhpMyAdmin
  3. Then on the left-hand side, find the database that has your WordPress is installed in and select it
  4. Now, on the middle of the screen on the top, find SQL tab, then simply put in the below code:
SQL:
SELECT * FROM TableNaameHere;

An example if I wanted to gather all my registered users would be:
SQL:
SELECT * FROM wpqb_users;

Then to run the code, just hit the "Go" button, located to the center, right side of the page.

You can then highlight/export the result to excel for your needs.

Another unrelated example to give you an idea about how powerful this is, I usually look at all the available tables inside my WordPress database, then I might want to see all the posts in aa table format, I would do the below:
SQL:
SELECT * FROM wpqb_posts;

I hope this answers your question.
 

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
Hi, thanks for your detail explanation. I guess I need to better explain my use on this.

I use Ultimate Member to control application access level (of course), and I wanted to create a frontend admin access to be able to view users list of certain roles below the admin role.

Just like any web app that admin can view users/members list and can click edit to edit the data.

Your guide have 2 main problem for my usage:

[ 1 ] the data is not real-time for the admin.

[ 2 ] Ultimate Member allow custom register form with custom field, Ultimate Member will handle the custom field their way, similar to ACF I guess. So in the WP USER MySQL table, it doesn't not contain the custom fields.

WPDataTables can work with your way to solve the real-time data for admin cause it make new query when the table load.

But it doesn't solve the custom fields problem. Please advice, thank you.
 

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
I find it easy to find a plugin to display Custom Post Type, such as WPdataTables.

But I can't find anything for Users with custom fields yet.
 

SharkTanker

Tech Guru
Trusted Uploader
Oct 30, 2018
388
648
93
corporatehitech.com.au
I find it easy to find a plugin to display Custom Post Type, such as WPdataTables.

But I can't find anything for Users with custom fields yet.
Not sure about the plugins mate, using SQL is much better because you have full power and accessibility, as well as flexibility to display any type of data you need.
 
  • Like
Reactions: markz

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
@Jano Buddy, can advice on this part? I'm not very familiar with SQL query.

I wanted to try get users data as what you advice, but I need to get link data from "usermeta" table as well.

The relation field is "user_id" on "usermeta" table.

How the MySQL query will look like? Can you give me an example so that I can learn from your example, thanks in advance.
 

SharkTanker

Tech Guru
Trusted Uploader
Oct 30, 2018
388
648
93
corporatehitech.com.au
@Jano Buddy, can advice on this part? I'm not very familiar with SQL query.

I wanted to try get users data as what you advice, but I need to get link data from "usermeta" table as well.

The relation field is "user_id" on "usermeta" table.

How the MySQL query will look like? Can you give me an example so that I can learn from your example, thanks in advance.
What do you mean... I don't understand what sort of data you're after...
This should show all user data, is that what you're after?
SQL:
SELECT * FROM wpqb_usermeta;
 

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
Please allow me to explain again.

I have this two table in my WP DB, wp_users and wp_usermeta.

To get the list of users, yes the following query do the job:
SQL:
SELECT * FROM wpqb_usermeta;

But I also need the wp_usermate included in the query result as well. The wp_usermeta include the custom fields I need for users.

I hope this explain better.
 

SharkTanker

Tech Guru
Trusted Uploader
Oct 30, 2018
388
648
93
corporatehitech.com.au
Please allow me to explain again.

I have this two table in my WP DB, wp_users and wp_usermeta.

To get the list of users, yes the following query do the job:
SQL:
SELECT * FROM wpqb_usermeta;

But I also need the wp_usermate included in the query result as well. The wp_usermeta include the custom fields I need for users.

I hope this explain better.
What is a "wp_usermate" that you refer to?
 

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
I try the following query but it's not working because of the way usermeta is stored.

SQL:
SELECT * FROM wp_users INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id

For only 2 users in the DB, the above query generate 100 rows of data instead of 2 rows.
 

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
Found the right SQL Query to get the right result, for anyone who need it, here is the query:

SQL:
SELECT
    u.id,
    u.user_email AS email,
    (select meta_value from wp_usermeta where user_id = u.id and meta_key = 'first_name' limit 1) as first_name,
    (select meta_value from wp_usermeta where user_id = u.id and meta_key = 'last_name' limit 1) as last_name,
    (select meta_value from wp_usermeta where user_id = u.id and meta_key = 'postcode' limit 1) as postcode
FROM wp_users u
 

markz

Active member
Trusted Uploader
Jun 21, 2019
174
36
28
What is a "wp_usermate" that you refer to?

Sorry that was my typo error. Should be "wp_usermeta".

Now I'm looking for way to filter the result by "role", any tips or hints?
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu