如果存在这样的键,我试图首先获取按数字 meta_key 排序的自定义帖子列表,如果没有键,则继续按标题排序。
我是说:
- AObject (object_order => 1)
- FObject (object_order => 2)
- BObject (object_order => 3)
- AObject (object_order => NULL)
- BObject (object_order => NULL)
- CObject (object_order => NULL) ... 等等。
我有这样的代码:
$properties_for_map = array(
'post_type' => 'property',
'posts_per_page' => -1,
'meta_key' => 'object_order',
'orderby' => 'meta_value_num title',
'order' => 'ASC',
'tax_query' => $tax_query
);
但它只显示带有元键的帖子。我试图在网站上找到答案,并找到了一些示例,但不太了解它们。也许有人可以帮助我并解释这种方法。
更新1: 可以这样做吗?
$properties_for_map = array(
'post_type' => 'property',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => object_order,
'compare' => 'EXISTS',
),
array(
array(
'key' => object_order,
'compare' => 'NOT EXISTS',
),
),
),
'orderby' => array( 'meta_value_num' => 'ASC', 'title' => 'ASC' ),
'tax_query' => $tax_query
);