Okay
  Public Ticket #3186584
wp_capabilities - display only the role
Closed

Comments

  • Gernot Rominger started the conversation

    Hello support team

    I'm trying to create a table with username and user role. However, the complete entry is always displayed to me as a role. But I just like the role.

    Display e.g.: a:1:{s:10:"subscriber";b:1;}
    he should show: subscribe

    SQL code:

    select
     wp_users.ID AS 'User ID',
     wp_users.display_name AS 'Name',
        max(if(wp_usermeta.meta_key = 'eintrFirma', wp_usermeta.meta_value, null)) as Eintritt,
        max(if(wp_usermeta.meta_key = 'ersthelferPOLL', wp_usermeta.meta_value, null)) as Ersthelfer,
        max(if(wp_usermeta.meta_key = 'diesnt', wp_usermeta.meta_value, null)) as Dienstverhaeltniss,
        max(if(wp_usermeta.meta_key = 'wp_capabilities', wp_usermeta.meta_value, null)) as Role
    from wp_users
    inner join wp_usermeta
    on wp_users.ID = wp_usermeta.user_id
    group by wp_users.ID


    Thank you


  •  1,850
    Miloš replied

    Hi, Gernot 

    Sorry for the waiting time.

    -

    Please be advised that writing custom SQL Queries or debugging Queries does not fall under what our support covers,

    but we will do our best to see if we have any working example or advice that might help you start in the right direction.

    -

    1.

    For example, we had a user who wanted to achieve filtering of tables per user role,

    i will share that solution with you, perhaps you can find it useful, for the part that compares user role.

    -

    If the dependency is a user role, 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.

    -


    2.

    In your use-case, though, i realise that you are trying to somehow "split" the values being pulled from the JSON data of the user meta table(s).

    As i mentioned, this does not fall under our support, because a high level of custom work is needed to write such SQL Query.

    I will give you this useful article , where you can learn How To Use JSON.parse() and JSON.stringify(),

    you can also search resources such as Stack Overflow, where a lot of users have tried similar solutions, like to split up the JSON values being pulled from the database.

    -

    I will also check with our 2nd level Team to see if they can provide any additional advice for you and will report back once they check everything.

    Let me know if these examples i sent helped you get your solution.

    Thank you


    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 | 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

  •  1,850
    Miloš replied

    Hi, Gernot

    The senior Team has been quicker than i expected, 

    I got advised b, they looked at all the details.

    What you would need to do here is to unserialize the JSON data.

    This falls under advanced MySQL, and unfortunately, it goes beyond the scope of our support.

    You will have to search for solutions, for example, such as this one from Stack Overflow

     i hope it helps.

    We wish you all the best.

    Of course, please don't hesitate to open new tickets if you have any new/unrelated questions and we will do our best to help you.

    Thank you


    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 | 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