I am working on a custom report of member data for a WordPress site. Some of the fields I need to include in the report are stored in the wp_usermeta table, but when I iterate through each member to retrieve that data, it eventually times out.
I’m currently using get_user_meta() because it seemed faster than doing the queries manually, but it still times out. There are about 5,600 users to process. It gets through 4000 of them just fine, but if I try to run it on the full set, it inevitably times out. Is there a better way to do this? Is there a way to pull bulk data from the wp_usermeta table instead of doing it separately for each user? I thought of maybe trying to pull down the entire usermeta table in one query and using PHP to manipulate it, but there are over 540,000 rows in that table…
Here’s where I’m at so far…
require_once( "db_connection.php" );
require_once( "../wp-config.php" );
$q = "SELECT ID,user_login,user_email,last_login,display_name FROM wp_users WHERE user_email='' ORDER BY user_login ASC;";
$r = mysql_query( $q );
$members = array();
while ( $member = mysql_fetch_array( $r ) ) {
$usermeta = get_user_meta($member['ID']);
$members[$member['ID']] = $member;
$members[$member['ID']]['meta'] = $usermeta;
}
echo "<pre>n";
var_dump( $members );
echo "</pre>n";
Thanks so much for any help/advice!
Well, I tried the “pull down everything” approach and it seems to work without timing out. Here’s my modified approach:
It’s too bad get_user_meta() doesn’t work for bulk data – it would be nice if we could pass it an array of IDs and fields we want, for example, and get a multidimensional array back… but I guess this way works for now, it’s just a little cumbersome.