我已经查过了,到目前为止还没有找到有效的答案。我有一个带有以下参数的WP\\U查询:
$args = array(
\'post_status\' => \'publish\',
\'post_type\' => \'listing\',
\'meta_key\' => \'client_feedback_score\',
\'orderby\' => \'client_feedback_score\',
\'order\' => \'DESC\'
);
$query = new WP_Query($args);
我想按自定义帖子字段对结果排序
client_feedback_score
, 从最低到最高。但这似乎不起作用。。。有人能给我指出正确的方向吗?
EDIT (SOLVED):
多亏了Milo的回答,下面是按数值元排序的工作代码:
$args = array(
\'post_status\' => \'publish\',
\'post_type\' => \'listing\',
\'meta_key\' => \'client_feedback_score\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\'
);
SO网友:ewroman
如果元值不是数字,例如,如果它是日期值;然后可以添加参数meta_type => DATE
.可能的值为;\'NUMERIC\', \'BINARY\', \'CHAR\', \'DATE\', \'DATETIME\', \'DECIMAL\', \'SIGNED\', \'TIME\', \'UNSIGNED\'
.
元类型的查询如下:
$args = array(
\'post_status\' => \'publish\',
\'post_type\' => \'listing\',
\'meta_key\' => \'client_feedback_score\',
\'orderby\' => \'meta_value_num\',
\'meta_type\' => \'DATE\',
\'order\' => \'DESC\'
);