How to pull certain data from a meta_value in mysql

I have a table inside wordpress which is wp_usermeta with the meta_key filed and a value called wp_s2member_custom_fields which holds a bunch of concatenated values like below.

How can I extract the data next to monthly_uniques inside this value?

Read More
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:"128";
s:15:"twitter_account";
s:31:"http://twitter.com/mytwitterpage";
s:17:"twitter_followers";
s:3:"392";}

In actual fact al these values are on one line, put them on separate lines for clarity

I need to pull this data in different ways to show reports. What do I add the below statement to pull montly_uniques, city, zip_code, etc?

Related posts

Leave a Reply

1 comment

  1. When WordPress enters an array into its database, it does something called Serializing, where it turns an array into the format of the string you supplied. To reverse this process and get back the same array, you simply need to run that string above through PHP’s built-in unserialize() function, which will return an associative array in the manner you mentioned above.

    So something like this:

    $string = '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:"128";s:15:"twitter_account";s:31:"http://twitter.com/mytwitterpage";s:17:"twitter_followers";s:3:"392";}';
    
    $array = unserialize($string);
    
    $array['monthly_uniques']; //This will give you the monthly_uniques field.