My wp_usermeta table has 4 columns, umeta_id | user_id | meta_key | meta_value
Image of table:
One of the columns has serialized data – wp_s2member_custom_fields. How can I unserialize from mysql or output with php to see all of my users data within the serialized column?
Here is a breakdown of the serialized data:
wp_s2member_custom_fields
a:12:{
s:7:"country";
s:2:"CA";
s:4:"city";
s:8:"Brampton";
s:5:"state";
s:7:"Ontario";
s:8:"zip_code";
s:6:"L6T4E7";
s:3:"age";
s:13:"25â34 years";
s:8:"blog_url";
s:22:"http://www.blog.com";
s:16:"blog_description";
s:106:"A blog about blogging";
s:15:"monthly_uniques";
s:4:"1000";
s:13:"facebook_page";
s:55:"http://www.facebook.com/myfacebookpage";
s:14:"facebook_likes";
s:3:"1428";
s:15:"twitter_account";
s:31:"http://twitter.com/mytwitterpage";
s:17:"twitter_followers";
s:3:"5849";}
Fetch the data from the database and use PHP’s
unserialize()
. There’s no way of doing this in MySQL (or any other DB) and it’s the main reason that most developers prefer to just write comma-separated valies in their tables.WordPress stores arrays/objects in the database by serializing them, so usually the retrieval function is what you want to look for since it will return the data unserialized.
In this case, it’s user_metadata, so you need to use the function get_user_meta(), which you provide the $user_id and $key parameters to retrieve it.
In your example, it would be something like this:
I hope that helps and makes sense…
NOTE:
The WordPress Codex is a priceless resource!