在一个WP_User_Query
电话:
我正在使用以下(简化)代码构建查询:
// custom user role
$arguments = array(
\'role\' => \'member\'
);
// number and offset
$arguments[\'number\'] = 10;
$arguments[\'offset\'] = 0;
$meta = array();
$meta[\'relation\'] = \'AND\';
// filter one (array)
$meta[] = array(
\'key\' => \'field-one\',
\'value\' => $values,
\'compare\' => \'IN\'
);
// filter two
$meta[] = array(
\'key\' => \'field-two\',
\'value\' => 0,
\'compare\' => \'=\'
);
// filter three
$meta[] = array(
\'key\' => \'field-three\',
\'value\' => 0,
\'compare\' => \'=\'
);
// even more filter
foreach( $filter as $key => $value ) {
$meta[] = array(
\'key\' => \'field-\' . $key,
\'value\' => $value,
\'compare\' => \'LIKE\'
);
}
$arguments[\'meta_query\'] = $meta;
// orderby
$arguments[\'meta_key\'] = \'last_name\';
$arguments[\'orderby\'] = \'meta_value\';
$query = new WP_User_Query(
$arguments
);
在我的localhost(MySQL版本5.6.23)上,它正确地返回结果和正确的
$query->total_users
. 在生产站点(MySQL版本5.5.42-37.1-log)
$query->get_results()
为空,但
$query->total_users
显示任意数字。
当我打印WP_User_Query
对象我可以检查生成的SQL查询,该查询在本地主机和生产服务器上都是相同的:
DISTINCT SQL_CALC_FOUND_ROWS wp_users.* [query_from] => FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) INNER JOIN wp_usermeta AS mt1 ON ( wp_users.ID = mt1.user_id ) INNER JOIN wp_usermeta AS mt2 ON ( wp_users.ID = mt2.user_id ) INNER JOIN wp_usermeta AS mt3 ON ( wp_users.ID = mt3.user_id ) INNER JOIN wp_usermeta AS mt4 ON ( wp_users.ID = mt4.user_id ) INNER JOIN wp_usermeta AS mt5 ON ( wp_users.ID = mt5.user_id ) [query_where] => WHERE 1=1 AND ( ( ( wp_usermeta.meta_key = \'last_name\' AND ( ( mt1.meta_key = \'field-one\' AND CAST(mt1.meta_value AS CHAR) IN (\'professional\',\'member\',\'junior\') ) AND ( mt2.meta_key = \'field-two\' AND CAST(mt2.meta_value AS CHAR) = \'0\' ) AND ( mt3.meta_key = \'field-three\' AND CAST(mt3.meta_value AS CHAR) = \'0\' ) AND ( mt4.meta_key = \'field-four\' AND CAST(mt4.meta_value AS CHAR) LIKE \'%my-value%\' ) ) ) AND ( mt5.meta_key = \'wp_capabilities\' AND CAST(mt5.meta_value AS CHAR) LIKE \'%\\"member\\"%\' ) ) ) [query_orderby] => ORDER BY wp_usermeta.meta_value ASC [query_limit] => LIMIT 20 )
你知道这有什么问题吗?