尝试将查询参数修改为:
$options[\'ind_start\'] = array(
\'label\' => \'Start Date (Earliest)\',
\'query_args\' => array(
\'meta_query\' => array(
\'start_date_query\' => array(
\'key\' => \'start_date\',
\'compare\' => \'EXISTS\', // Optional
),
)
)
);
meta_query
- 将只包括带有
start_date
价值
然后添加WP查询顺序过滤器:
function my_order_filter($orderby, $obj){
global $wpdb;
// Put here some conditional logic if you want to apply this only for a specific query.
$new_order_query_part = "{$wpdb->postmeta}.meta_value = \'-\' ASC, {$wpdb->postmeta}.meta_value ASC ";
if( trim($orderby) ){
$orderby = $new_order_query_part . \', \' . $orderby;
} else {
$orderby = $new_order_query_part;
}
return $orderby;
}
add_filter( \'posts_orderby_request\', \'my_order_filter\', 10, 2 );
此筛选器将应用于所有查询。如果只需要将订单功能添加到特定查询,那么在将新订单应用于请求之前,请使用一些条件筛选。