I would like to display posts that have a certain value in a meta field first. I would like to display posts that have a certain value in a meta field first. I have tried it with meta_query and orderby. Unfortunately, only the posts that have exactly this value are displayed, not the others.
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
'paged' => $paged,
'meta_query' => array(
'customid' => array(
'key' => 'custom_id',
'compare' => 'LIKE',
'value' => 12345
),
'customidexists' => array(
'key' => 'custom_id',
'compare' => 'EXISTS'
)
),
'orderby' => array(
'customid' => 'ASC',
'customidexists' => 'ASC',
),
);
Posts should be output in the following order:
[
{
"title": "test1",
"custom_id": 12345
},
{
"title": "test2",
"custom_id": 12345
},
{
"title": "test1",
"custom_id": 45236
},
{
"title": "test1",
"custom_id": 65442
}
]