我在使用ACF插件创建的用户配置文件中有一些meta\\u字段。我正在尝试运行查询以获取具有以下条件的用户:
用户必须具有meta\\u字段jogador_profissional == true
用户列表必须按meta\\u字段排序quantidade_corretas (ASC)
以及tempo_total (DESC)
. 两者都是数值这是我的问题:
$args = array(
"fields" => "ids",
"meta_key" => "jogador_oficial",
"meta_value" => true,
"meta_query" => array(
"relation" => "AND",
"query_one" => array(
"key" => "quantidade_corretas"
),
"query_two" => array(
"key" => "tempo_total"
),
),
"orderby" => array(
"query_one" => "DESC",
"query_two" => "ASC"
),
);
$user_query = new WP_User_Query($args);
$users = $user_query->get_results();
它运行正常,但我怀疑此查询将数值视为字符串值:例如,
9 > 100
或
2 > 18
.
使此订单以数字方式工作,我做错了什么?
谢谢
最合适的回答,由SO网友:shanebp 整理而成
要将元值计算为数字,请使用meta_value_num
.
尝试:
$args = array(
"fields" => "ids",
"meta_key" => "jogador_oficial",
"meta_value" => true,
"meta_query" => array(
"relation" => "AND",
"query_one" => array(
"key" => "quantidade_corretas"
"orderby" => "meta_value_num",
"order" => "DESC"
),
"query_two" => array(
"key" => "tempo_total"
"orderby" => "meta_value_num",
"order" => "ASC"
),
),
);