英文:
Set a 2nd orderby value for a query action?
问题
I'm trying to order some custom posts by a meta_value, and then secondly order them by the title. How can I set a second orderby value in the below action?
在下面的操作中,如何设置第二个 orderby 值,以便按 meta_value 排序自定义文章,并且其次按标题排序?
add_action('elementor/query/jet-smart-filters', function($query) {
$query->set('meta_key', 'fuel_type_id');
$query->set('orderby', 'meta_value_num title'); // 设置第二个排序字段为标题
$query->set('order', 'ASC');
});
英文:
I'm trying to order some custom posts by a meta_value, and then secondly order them by the title. How can I set a second orderby value in the below action?
add_action( 'elementor/query/jet-smart-filters', function( $query ) {
$query->set( 'meta_key', 'fuel_type_id' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
});
答案1
得分: 1
Use this code to set a second-order by value in your above action.
add_action('elementor/query/jet-smart-filters', function ($query) {
$query->set('meta_key', 'fuel_type_id');
$query->set('orderby', array('meta_value_num', 'title'));
$query->set('order', 'ASC');
});
You can also set the order using ascending/descending for each order by value separately by passing in the array. For that, you can use the below example.
$query->set('orderby', array(
'meta_value_num' => 'ASC',
'title' => 'DESC'
));
英文:
Use this code the set a second order by value in your above action.
add_action( 'elementor/query/jet-smart-filters', function( $query ) {
$query->set( 'meta_key', 'fuel_type_id' );
$query->set( 'orderby', array( 'meta_value_num', 'title' ) );
$query->set( 'order', 'ASC' );
});
You can also set the order using ascending/descending for each order by value separately by passing in the array. for that, you can show the below example.
$query->set( 'orderby', array(
'meta_value_num' => 'ASC',
'title' => 'DESC'
) );
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论