Jump to content

Complicated querty (for me) dealing with serialized data...


Jim R

Recommended Posts

I'm dealing with data that WordPress creates for Users when they register and subscribe, and to use it for other purposes, I have to wrap my head around serialized data.  It's not sinking in well.  The below code works well for what I wanted at the time. 

 

It takes into consideration where the Subscriber lives (divided up into five areas) and counts how many I have.  That is noted by wp_s2member_custom_fields and ANY s2member_level.  There are three levels, and I need to actually note how many there are at each Member level. 

 

There is another line of data for each user_id

meta_key = wp_capabilities

meta_value = a:1:{s:15:"s2member_level2";s:1:"1";}

 

 


$custom = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_s2member_custom_fields" AND user_id IN (SELECT user_id FROM wp_usermeta WHERE meta_value LIKE "%s2member_level%")';
$c_results = mysql_query($custom);

$region = array();

while($line = mysql_fetch_assoc($c_results)) {

$meta_value = unserialize($line['meta_value']);

$region[$meta_value['county']]++;
};

foreach ($region as $key => $value) {

echo "Region $key: $value members<br>";
}

Link to comment
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.