Okay
  Public Ticket #2761315
Querying Meta Tables
Closed

Comments

  • Nano Schmidt started the conversation

    Hi, 


    I am looking to pull user information from my wordpress website. I am using wpDataTables as the plugin to access the data on my site. The type of data I want to query is in the "wp_usermeta" table. However, I am not entirely sure what the name of the attributes/meta keys I am looking for are called. I am not familiar with meta tables in general. 


    To give more context...

    I help run an e-learning test prep business. We built our e-learning platform with a plugin called "LearnDash". On this plugin students can take quizzes. We want the quiz data from the students. The quiz data may be in multiple places (tables) but the quiz score is stored in the "wp_usermeta" table. I am having trouble using wpDataTables to retrieve the quiz score and other necessary attributes. 


    So...

    1. Can I use wpDataTables to access meta tables, specifically the wp_usermeta table?

    2. If so can I use SQL/ mySQL to retrieve this data? (versus PHP) 

    3. Must I know the name of the meta key to find the quiz score? If so how do I find the name of the meta key to find the user quiz score of each quiz?   

    Please let me know if you have any questions. I am so close to getting the quiz scores I know they are in there! I don't know what I am missing so I think its time to get some outside help.


    Thanks, 


    Nano



  • [deleted] replied

    Hi Nano

    Thank you for reaching out to us.

    1. and 2. yes, but unfortunately we can't help you with that since it's custom queries. 

    Please have a look at our WP database query constructor, Please note: this tool is not an ultimate query generator. It simply constructs a suggestion of a query. We are constantly working to improve it, but SQL is such a complicated and flexible language that full automation for constructing queries is next to impossible. 

    Consequently, the more complicated the query, the higher is the probability that it will not return exactly what you need. So, you will often need to play around with the resulting query.

    3. You do need to know what you are pulling from the database, and most likely you will need to work on the query to get it to work correctly.

  • Nano Schmidt replied

    Hi Blaženka, 


    I appreciate you answering all my questions! I did some more work on it and dug for the meta key name and almost got what I wanted. I queried the right meta key however the values that show are all jumbled up. So through a quick google search I think I learned that Wordpress automatically conducts a PHP serialized array on metadata that doesn't receive a specific formatting from the developer. Apparently it is done often with plugins and the data (metadata) the plugin will bring on. So I assume LearnDash did not specify the formatting of metadata that is funneled into the table "wp_usermeta ". 


    My Questions...


    1. Can I use wpDataTables to unserialize the values I have queried from the wp_usermeta?

    2. If so is that done in PHP or SQL or both? 

    3. Does wpDataTables support PHP (as it does with SQL)?


    I have attached a screenshot of what I am talking about so you can get a visual. Please let me know if you have any questions and again thank you for your help!


    Best, 


    Nano

  • [deleted] replied

    Hi Nano

    You cannot unserialize the data through a query. At least not easily. But please have a look at this https://stackoverflow.com/questions/5335970/unserialize-through-query-at-database-level-itself

    That's a serialized PHP Array, so it needs to be unserialized with a PHP Adapter, or passed into a PHP array.

    We do support creating tables from serialized PHP Array. Please have a look at our documentation: https://wpdatatables.com/documentation/creating-wpdatatables/creating-wpdatatables-from-serialized-php-array/

    I hope this helps, do let us know it there is anything else we can assist you with.


  • Nano Schmidt replied

    Hi Blaženka, 

    I looked at the first article you sent and it looks like it can be done using mySQL but it looks tough. I also think it would not be optimal for up-to-date and current data. 

    Can I use a PHP adapter with wpDataTables to unserialize my data? 

    If i did decide to create tables using serialized PHP array will it be up-to-date and current data? To elaborate, our students will be taking many quizzes throughout the course so we want to build a page so these students can view their quiz performance (whether its how they are performing over time or if they want to see how they perform relative to subject). So a big requirement we want to ensure is that the charts and graphs the students will see is current data from every quiz they have taken with no manual data inputs from the management side.

    If you have any questions let me know!


    Best, 


    Nano




  • [deleted] replied

    Hi Nano

    Sorry for the late response, we're Christian Orthodox, so we had non-working days for Easter.

    To be honest I am not sure, let me forward this to our developers and get back to you as soon as I get a response from them.

    Thank you for your time and patience.

  • [deleted] replied

    Hi Nano

    Thank you for your patience.

    So what our development team suggests is if you can prepare the serialized PHP Array, you could create a table linked to a serialized PHP Array and it would work, but the table wouldn't be editable.

    I hope this helps, do let us know if you need any further assistance.

  • Nano Schmidt replied

    Hi Blaženka, 


    No worries at all! Do you know if I could still make that table into charts and graphs? Or would the table I produce form the linked serialized PHP Array only be a table and thats it? 


    Thanks, 


    Nano

  • [deleted] replied

    Hi Nano

    You can create charts from all types of tables except from simple tables. So to answer your question, yes, you would be able to create a chart from your serialized PHP Array based table.

    Do let us know if you need any further assistance.

  • Nano Schmidt replied

    Hi Blaženka, 


    Awesome! Thats all that really matters. As long as i can create charts and graphs for the students and its current data from their quizzes then I'm good to go. I might shoot some more questions down the line when I start implementing stuff but again thank you so much for your help!


    Best, 


    Nano


  • [deleted] replied

    Thanks in advance.

    You are most welcomesmile.png

    Please don't hesitate to open a new ticket if there i anything else we can assist you with, we are always happy to help.

    May I ask you for a small favor if you don’t mind? 

    Can you, please, leave a review on the Lite version of wpDataTables if you have an account at wordpress.org and have a couple of minutes? No need to write any specific text.

    It’d mean a lot to us.