I’m interested in purchasing WP data tables and the one feature I’m having trouble finding is the ability to conditionally show records in a table if a user belongs to a custom role.
For example, if I have a products table where products belong under a vendor, can I only show the products that are mapped to the currently logged in vendor? I want to map data fields to custom user roles.
If I understood your request correctly, you're looking for the "Users see and edit only their own data" feature. Please take a look at the linked documentation and let me know if you have some follow-up questions.
If the dependency is a user role, for example, we could make it work.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
So, then I go to create an SQL query based table which will display entries based on user roles using this query:
SELECT new_table.id AS ID,
new_table.role AS Role,
new_table.product AS Product,
new_table.amount AS Amount
FROM wp_wpdatatable_6 AS new_table
JOIN wp_usermeta AS new_table_1
ON new_table_1.user_id = %CURRENT_USER_ID%
AND new_table_1.meta_value LIKE CONCAT('%', new_table.role, '%')
When I'm logged in with user ID = 1, I see this:
When I'm logged in with user ID = 4, I see the same thing. And when I'm logged in as one of the subscribers, I can only see the rows where role = subscriber:
The only difference is that as a subscriber I don't have access to the back-end, so this confirms it is working on both front and back.
So, we're only left with hiding unnecessary columns, adding names, and so on.
I’m interested in purchasing WP data tables and the one feature I’m having trouble finding is the ability to conditionally show records in a table if a user belongs to a custom role.
For example, if I have a products table where products belong under a vendor, can I only show the products that are mapped to the currently logged in vendor? I want to map data fields to custom user roles.
Is this currently possible?
Hello Ben
Thank you for your interest in our plugin.
If I understood your request correctly, you're looking for the "Users see and edit only their own data" feature. Please take a look at the linked documentation and let me know if you have some follow-up questions.
If the dependency is a user role, for example, we could make it work.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
So, then I go to create an SQL query based table which will display entries based on user roles using this query:
When I'm logged in with user ID = 1, I see this:
When I'm logged in with user ID = 4, I see the same thing. And when I'm logged in as one of the subscribers, I can only see the rows where role = subscriber:
The only difference is that as a subscriber I don't have access to the back-end, so this confirms it is working on both front and back.
So, we're only left with hiding unnecessary columns, adding names, and so on.
Hope this helps.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Wow, this is exactly what I’m looking for. Thank you for the detailed response.
You're welcome, Ben, glad I could help.
If you need some further assistance, please feel free to reach out to us.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables