有时候我们遇到文章多字段多重排序,或者说一个字段排序同时又得判断是否含有另一个字段或另一个字段值等于某个值,看以下代码:

<?php
//多个字段多重排序
$args = array(
\'post_type\'=> \'words\',
\'meta_query\' => array(
array(
\'key\' => \'word_count\',
\'orderby\' => \'meta_value_num\',
\'order\' => DESC
,
),
array(
\'key\' => \'title\',
\'orderby\' => \'meta_value\',
\'order\' => DESC
),
array(
\'key\' => \'word_type\',
\'orderby\' => \'meta_value\',
\'order\' => DESC
),
),
);
$query = new WP_Query( $args );


//一个字段排序+其他字段
query_posts(
array(\'post_type\' => \'services\',
\'order\' => \'ASC\',
\'meta_key\' => \'some_key\',
\'orderby\' => \'meta_value\', //or \'meta_value_num\'
\'meta_query\' => array(
array(\'key\' => \'order_in_archive\',
\'value\' => \'some_value\'
)
)
)
);
?>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注