前提・実現したいこと
wordpressで年度別表示アーカイブを作成しようとしているのですが、うまくいきません。
例えば、2022年3月の投稿をすると、2021年度として表示されるようにしたいのですが、表示が消えてしまいます。
ただし、2021年12月以前に1つでも投稿があれば2022年3月の投稿も表示されます。
年跨ぎの1月〜3月の投稿を単体でした場合のみ表示されないといった現象が起きており困っています。
表示される投稿パターン
■2021年度
2022年2月10日
2021年12月23日
2021年8月5日
表示されない投稿パターン
■2021年度
2022年2月10日
ご教示いただけましたら幸いです。
よろしくお願いいたします。
該当のソースコード
php
1<ul class="p-news__list"> 2 <?php 3 $this_year = get_the_date('Y'); 4 $args = array( 5 'post_type'=>'news' 6 'paged' => $paged, 7 'posts_per_page'=> '10', 8 'date_query' => array( 9 array( 10 'after' => array( 11 'year' => $this_year, 12 'month' => 4, 13 'day' => 1, 14 ), 15 'before' => array( 16 'year' => $this_year + 1, 17 'month' => 3, 18 'day' => 31, 19 ), 20 'inclusive' => true, 21 ), 22 ), 23 ); 24 $wp_query = new WP_Query( $args ); 25 ?> 26 <?php if ($wp_query->have_posts() ) : ?> 27 <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> 28 <li class="p-news__item" id="post-<?php the_ID(); ?>"> 29 <a href="<?php the_field('external_link'); ?>" class="c-card"> 30 <figure class="c-card-figure"> 31 <img src="<?php the_field('news_thumbnail'); ?>" alt="" /> 32 </figure> 33 <div class="c-card-wrap"> 34 <span class="c-card-date"><?php the_time('Y.m.d') ?></span> 35 <p class="c-card-title c-card-title--big"><?php the_title() ?></p> 36 </div> 37 </a> 38 </li> 39 <?php endwhile; ?> 40 <?php endif; ?> 41 <?php wp_reset_postdata(); ?> 42 </ul>
回答1件
あなたの回答
tips
プレビュー