イベント開催スケジュールを開催日の早い順でかつ同じ日で時間の早いイベント順に並べて出力する必要があったので、下記のようなWP Queryを書いて可能にしました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php $args = array( 'posts_per_page' => 10, 'meta_query' => array( 'customfield_01' => array( 'key' => 'start_date', //「日」のフィールド名 ), 'customfield_02' => array( 'key' => 'start_time', //「時間」のフィールド名 ) ), 'orderby' => array( 'customfield_01' => 'ASC', 'customfield_02' => 'ASC' ) ); $the_query = new WP_Query( $args );// ループ if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); endwhile; endif; // 投稿データをリセット wp_reset_postdata(); ?> |
(参考)
WP_Query get_posts 複数のカスタムフィールドの値で順序制御
Order by multiple meta keys in WP Query