Advanced Custom Fields のアドオン Repeater Fieldのループ内で表示がうまくできない、と相談があり。
よくわかんないんだけど、get_postsで表示させた。リピーターフィールドの値をタームに入れて、最新の日付を表示。
$my_postsの中身みて、必要なものを取り出す。取り出した日付の値を、strtotimeで整形しています。
これで良かったのだろうか…。
<?php $category = get_sub_field('xxxx'); $args = array( 'post_type' => 'xxxx', 'posts_per_page' => 1, 'tax_query' => array( array( 'taxonomy' => 'xxxxxx', 'field' => 'slug', 'terms' => $category, ), ), ); $my_posts = get_posts( $args ); if( $my_posts ) { $date = $my_posts[0]->post_date; ?> <p class="pickup">更新日:<?php echo date('Y.m.d', strtotime($date));?><time datetime="<?php echo date('Y.m.d', strtotime($date));?>"></time></p> <?php } ?>
テンプレートタグ/get posts
https://wpdocs.osdn.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/get_posts