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>";
}

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.