I am trying to sort categories by meta field position, but the problem is that if you sort by meta field, the query will not take into account other categories without this meta field.
Tried this:
$categories = get_terms([
'taxonomy' => 'nwb_cat',
'hide_empty' => false,
'meta_query' => [
'relation' => 'OR',
'position' => [
'key' => 'position',
'compare' => 'EXISTS'
],
'position_not' => [
'key' => 'position',
'compare' => 'NOT EXISTS'
],
],
'orderby' => [
'position' => 'ASC',
]
]);
Result: no sorting takes place Tried this:
$categories = get_terms([
'taxonomy' => 'nwb_cat',
'hide_empty' => false,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'position',
]);
Result: The sorting works correctly, but only those categories that have the meta field position are displayed. PS. This field will not be filled by default. How can this issue be resolved?