I have assigned individual personnel numbers to my users. Now I would like to create a table (e.g. vacation plan) that recognizes the personnel number of the logged-in user and filters the table based on this condition. The user should only see the line that contains data for their personnel number. Personnel number = pnr,
I am sorry to disappoint you, but we don't have an easy built-in solution to filter a table like this, because we do not have a placeholder available for filtering that can take your custom "personnel number" field, for example, if you added it somehow to the User's MetaData in your WordPress Database.
You can check all our currently available Dynamic Placeholders here, which can be used from the 'currently logged User' for easy filtering solutions.
For example, when it comes to the "Currently logged user" placeholders, we have these :
%CURRENT_USER_ID% – this placeholder will be replaced with the ID of a currently logged-in user (if the user is logged in).
%CURRENT_USER_LOGIN% – this placeholder will be replaced with the currently logged-in username (if the user is logged in).
%CURRENT_USER_EMAIL% – this placeholder will be replaced with the email of the currently logged-in user (if the user is logged in).
%CURRENT_USER_FIRST_NAME% – this placeholder will be replaced with the First Name of the currently logged-in user. Provide a value here to be used for table generation.
%CURRENT_USER_LAST_NAME% – this placeholder will be replaced with the Last Name of the currently logged-in user. Provide a value here to be used for table generation.
So, if you had a Field that stores the currently logged username, for example - you might add this in your SQL Query on the "WHERE" statement like :
SELECT Column A,
Column B
... ( other Columns) ...
FROM TableName
WHERE ColumnName = '%CURRENT_USER_LOGIN%'
This way, if you had a Column in your Table that stores each User's UserName - the Table would filter the rows to only show the ones which match the currently logged username.
Can you tell me, do you have the 'personnel number' somehow linked to the WP User's MetaData so that each User, when they log in, this personnel number is linked to them?
If so, you can only try a custom solution.
You could 'group' users with Custom user roles ( you can add Custom Roles via a Membership Plugin or User Role Editor Plugin), and assign the appropriate 'personnel number' as a Custom Role to them - then try filtering like that.
Please note, custom work is not covered by our Support, we can only try to get you started with a custom idea.
Here is an example we made where you can use a Custom User Role to filter the Data in the SQL Table.
On this example, we use the default Roles like Administrator, Subscriber, Editor and so on - but you can use the same 'principle'/logic, just need to modify it for your specific custom User Roles for filtering.
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 subscriber I don't have access to 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.
Hello,
I have assigned individual personnel numbers to my users. Now I would like to create a table (e.g. vacation plan) that recognizes the personnel number of the logged-in user and filters the table based on this condition. The user should only see the line that contains data for their personnel number. Personnel number = pnr,
Example: Personnel number = tt-060
SELECT Urlaubsplan_2024.`pnr`,
Urlaubsplan_2024.`name`,
Urlaubsplan_2024.`2024-01-01`,
Urlaubsplan_2024.`2024-01-02`,
Urlaubsplan_2024.`2024-01-03`,
Urlaubsplan_2024.`2024-01-04`,
Urlaubsplan_2024.`2024-01-05`,
…
FROM Urlaubsplan_2024, wp_Stammdaten
WHERE 1=1
AND wp_Stammdaten.`pnr` = 'tt-060'
Hi Alexander,
Apology for the late reply.
I am sorry to disappoint you, but we don't have an easy built-in solution to filter a table like this, because we do not have a placeholder available for filtering that can take your custom "personnel number" field, for example, if you added it somehow to the User's MetaData in your WordPress Database.
You can check all our currently available Dynamic Placeholders here, which can be used from the 'currently logged User' for easy filtering solutions.
For example, when it comes to the "Currently logged user" placeholders, we have these :
So, if you had a Field that stores the currently logged username, for example - you might add this in your SQL Query on the "WHERE" statement like :
SELECT Column A,
Column B
... ( other Columns) ...
FROM TableName
WHERE ColumnName = '%CURRENT_USER_LOGIN%'
This way, if you had a Column in your Table that stores each User's UserName - the Table would filter the rows to only show the ones which match the currently logged username.
Can you tell me, do you have the 'personnel number' somehow linked to the WP User's MetaData so that each User, when they log in, this personnel number is linked to them?
If so, you can only try a custom solution.
You could 'group' users with Custom user roles ( you can add Custom Roles via a Membership Plugin or User Role Editor Plugin), and assign the appropriate 'personnel number' as a Custom Role to them - then try filtering like that.
Please note, custom work is not covered by our Support, we can only try to get you started with a custom idea.
Here is an example we made where you can use a Custom User Role to filter the Data in the SQL Table.
On this example, we use the default Roles like Administrator, Subscriber, Editor and so on - but you can use the same 'principle'/logic, just need to modify it for your specific custom User Roles for filtering.
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 subscriber I don't have access to 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 hope this helps.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
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