WP_Query get_posts 複数のカスタムフィールドの値で順序制御
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
// カスタムフィールド(数値のみ入力されるフィールド)
'meta_query' => array(
'customfield_01' => array(
'key' => 'customfield_01',
'type' => 'NUMERIC'
),
'customfield_02' => array(
'key' => 'customfield_02',
'type' => 'NUMERIC'
)
),
'orderby' => array(
'customfield_01' => 'DESC',
'customfield_02' => 'ASC'
)
);
?>
<?php $query = new WP_Query( $args ); ?>
この例だと’customfield_01’の値をもとに’DESC’(降順)を基本は並び替え、
もしその数値が同じだった場合は’customfield_02’の値を参照して、’ASC’(昇順)に並び替える。
参考:https://mathieuhays.co.uk/order-by-multiple-post-meta-in-wp-query/