[wp-hackers] get_users() exhausts memory with 'all_with_meta' argument

Otto otto at ottodestruct.com
Fri Jan 3 19:33:23 UTC 2014


On Fri, Jan 3, 2014 at 1:29 PM, Mike Walsh <mpwalsh8 at gmail.com> wrote:
> To answer some of questions - the opt-in aspect is exactly what is stored
> as meta data.  I took over this plugin a while back and this query model
> has been part of it long before I started working on it.  Basically it does
> a query for all users which have meta data and processes that.  The Codex
> indicates the meta query has been available since 3.5.0 and this plugin
> dates back to the 2.x days.

Cool. So instead of doing get_users(array('fields' =>
'all_with_meta')), change it to:

get_users(array(
'meta_key' => 'your-opt-in-key',
'meta_value' => 'your-opt-in-value',
) )

And you should be good to go, most likely. This will only get the
users opted in and it won't try to cache all the meta data for all the
users at once.

-Otto


More information about the wp-hackers mailing list