Okay
  Public Ticket #1159554
Fetch User Data
Closed

Comments

  • arunyogeshns started the conversation

    Hi,

    I would like to fetch users of specific role in wpdatatables. I have several custom fields that has to be fetched as well. I tried to fetch from mysql database but it doesn't help in fetching custom fields. So, I chose to fetch it from PHP serialize method, but for some reasons it doesn't happen. It would be great if you can help me in doing it. 

    Thanks in advance.

    Arun Yogesh.

  • arunyogeshns replied

    Hi,

    I have managed to get it done by MySQL. Below is the code:

    SELECT 
            wpu6_users.display_name AS n_user_display_name,
            t1.meta_value AS n_user_first_name,
            t2.meta_value AS n_user_phone, 
            wpu6_users.user_email AS n_user_user_email,
            t3.meta_value AS n_user_address_1,
            t4.meta_value AS n_user_address_2,
            t5.meta_value AS n_user_area,
            t6.meta_value AS n_user_city,
            t7.meta_value AS n_user_state,
            t8.meta_value AS n_user_country,
            t9.meta_value AS n_user_postcode
            FROM wpu6_users
            LEFT JOIN wpu6_usermeta AS t1 ON t1.user_id = wpu6_users.ID 
            LEFT JOIN wpu6_usermeta AS t2 ON t1.user_id = t2.user_id 
            LEFT JOIN wpu6_usermeta AS t3 ON t2.user_id = t3.user_id  
            LEFT JOIN wpu6_usermeta AS t4 ON t3.user_id = t4.user_id
            LEFT JOIN wpu6_usermeta AS t5 ON t4.user_id = t5.user_id 
            LEFT JOIN wpu6_usermeta AS t6 ON t5.user_id = t6.user_id  
            LEFT JOIN wpu6_usermeta AS t7 ON t6.user_id = t7.user_id
            LEFT JOIN wpu6_usermeta AS t8 ON t7.user_id = t8.user_id
            LEFT JOIN wpu6_usermeta AS t9 ON t8.user_id = t9.user_id
            WHERE t1.meta_key = 'billing_first_name' 
            AND t2.meta_key = 'billing_phone' 
            AND t3.meta_key = 'billing_address_1' 
            AND t4.meta_key = 'billing_address_2'
            AND t5.meta_key = 'mv_area' 
            AND t6.meta_key = 'billing_city' 
            AND t7.meta_key = 'billing_state'
            AND t8.meta_key = 'billing_country' 
            AND t9.meta_key = 'billing_postcode' 

    Now I am trying to display users based on role. Can anyone suggest the best way to do it in MySQL?

    Any help is greatly appreciated. 

    Thanks in advance.

  •  1,846
    Miloš replied

    Hi Arun Yogesh,
    Thank you for your purchase.


    We are glad that you found the solution,good job.
    If you have any more issues feel free to open a new ticket, we will gladly help.

    Best regards.

    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

  • arunyogeshns replied

    Hi,

    Additionally, help me in retrieving users based on role using below MySQL query.

    SELECT 
            wpu6_users.display_name AS n_user_display_name,
            t1.meta_value AS n_user_first_name,
            t2.meta_value AS n_user_phone, 
            wpu6_users.user_email AS n_user_user_email,
            t3.meta_value AS n_user_address_1,
            t4.meta_value AS n_user_address_2,
            t5.meta_value AS n_user_area,
            t6.meta_value AS n_user_city,
            t7.meta_value AS n_user_state,
            t8.meta_value AS n_user_country,
            t9.meta_value AS n_user_postcode
            FROM wpu6_users
            LEFT JOIN wpu6_usermeta AS t1 ON t1.user_id = wpu6_users.ID 
            LEFT JOIN wpu6_usermeta AS t2 ON t1.user_id = t2.user_id 
            LEFT JOIN wpu6_usermeta AS t3 ON t2.user_id = t3.user_id  
            LEFT JOIN wpu6_usermeta AS t4 ON t3.user_id = t4.user_id
            LEFT JOIN wpu6_usermeta AS t5 ON t4.user_id = t5.user_id 
            LEFT JOIN wpu6_usermeta AS t6 ON t5.user_id = t6.user_id  
            LEFT JOIN wpu6_usermeta AS t7 ON t6.user_id = t7.user_id
            LEFT JOIN wpu6_usermeta AS t8 ON t7.user_id = t8.user_id
            LEFT JOIN wpu6_usermeta AS t9 ON t8.user_id = t9.user_id
            WHERE t1.meta_key = 'billing_first_name' 
            AND t2.meta_key = 'billing_phone' 
            AND t3.meta_key = 'billing_address_1' 
            AND t4.meta_key = 'billing_address_2'
            AND t5.meta_key = 'mv_area' 
            AND t6.meta_key = 'billing_city' 
            AND t7.meta_key = 'billing_state'
            AND t8.meta_key = 'billing_country' 
            AND t9.meta_key = 'billing_postcode' 

  •  1,846
    Miloš replied

    Hi Arun,

    Please be advised that preparing MySQL queries for you is not included in plugin support, included support covers help with bugs and general inquiries for the plugin features, but requests like this can be done as a paid customization service. I can not write query for you because it is a policy of the company and it will be unfair to other customers that have similar requests.

    I can point you out to make a table using our wpdatatables constructor but there are some limitations.

    If you take a look at our documentation you can see that wpDataTables Constructor is just a helper:

    "Please note that WPDB query constructor is not an ultimate query generator, it just constructs a suggestion of a query. We constantly work on improving it, but SQL is such a complicated and flexible language that full automation for constructing queries is hardly possible. So the more complicated the query is, the higher is the chance that it will not return exactly what you need. So play around with the resulting query."

    Thank you for understanding.

    Best regards.

    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