Okay
  Public Ticket #2307848
Retrieve Data
Closed

Comments

  • Harjeet started the conversation

    Hello Team,

     have to Retrieve Data base on user role. Please assist me to how i can restrict table row base on user role. 


    Other way..

    I am using WpFusion plugin. So i want to retrieve data using fusion tag. 
    Here is the plugin link.
    https://wpfusion.com/

    Waiting for your reply on same.

    Thanks,
    Harjeet

  •  2,513
    Aleksandar replied

    Hello Harjeet

    Thank you for your purchase.

    You can retrieve data like this only with SQL Query based tables. For example, if I have this table:

    5458776907.png

    This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:

    7855603551.png
    6462766399.png
    7686895681.png

    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:

    9999185249.png

    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:

    2907856651.png

    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.

    Hope this helps.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia 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