在我的插件中,我使用以下说明获取帖子列表:
$args = array(
\'numberposts\' => -1,
\'offset\' => 0,
\'meta_query\' => array(
array(
\'key\' => \'metadata1\',
\'value\' => \'80\',
\'compare\' => \'<=\',
\'type\' => \'UNSIGNED\'
),
array(
\'key\' => \'metadata2\',
\'value\' => \'4.6\',
\'compare\' => \'<=\',
\'type\' => \'DECIMAL\'
),
),
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true );
$posts = get_posts($args);
foreach ($posts as $post) {
// some work on $post
}
我怎样才能订购这些帖子
metadata1
升序或按
metadata2
提升(请注意
metadata1
是无符号整数,并且
metadata2
是十进制数。)
最合适的回答,由SO网友:Mridul Aggarwal 整理而成
尝试meta\\u value\\u num
\'meta_key\' => \'metadata1\',
\'orderby\' => \'meta_value_num\'
将这两个参数添加到$args。将metadata1视为数字进行排序