我目前正在努力为wordpress网站实现一个功能。我想获得拥有该密钥的所有用户的计数pending_approval=\'true\'
和is_photographer=\'true\'
(位于wp_usermeta
. 如何才能做到这一点?我一直在搜索文档,但找不到合适的示例。
示例代码:
$users_sent_to_admin = new WP_User_Query(array(
\'meta_query\' => array(
array(
\'key\' => \'pending_approval\',
\'value\' => \'true\',
\'compare\' => \'=\'),
array(
\'key\' => \'is_photographer\',
\'value\' => \'true\',
\'compare\' => \'=\'
),
)
));
$users_sent_to_admin = new WP_Query($users_sent_to_admin);
最合适的回答,由SO网友:Chittaranjan 整理而成
我想你错过了relation
钥匙在这里。如果您希望在上述两个元值都匹配时提取用户,那么您应该如下使用
$users_sent_to_admin = new WP_User_Query(
array(
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'pending_approval\',
\'value\' => \'true\',
\'compare\' => \'=\'),
array(
\'key\' => \'is_photographer\',
\'value\' => \'true\',
\'compare\' => \'=\'
),
)
)
);