Wordpressのカスタムフィールドに
2017/03/12
のように日付を入れて投稿していて、7日以内のものを日付順番に並び替えるコードを書いています。
<ul class="mt30 txl"> <?php $metakey = 'sell'; // カスタムフィールドで設定した名前 $naninichimae = 7; // 何日前から表示するか $after = new DateTime(); $after = $after->modify('+'.$naninichimae.' days')->format('Y/m/d'); $today = new DateTime(); $today = $today->format('Y/m/d'); $args = array( 'meta_key' => $metakey, 'meta_query' => array( array( 'key'=> $metakey, 'value'=> $after, 'compare'=> '<', ), array( 'key'=> $metakey, 'value'=> $today, 'compare'=> '>=', ), 'relation'=>'AND' ), 'orderby' => 'meta_value', 'order' => 'ASC', 'type' => 'DATE' ); $the_query = new WP_Query( $args ); ?> <?php if ( $the_query->have_posts() ) : ?> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <span class="event-date"><?php echo get_post_meta( get_the_ID() , 'sell' ,true); ?></span> <p class="event-title"><a class="archive-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> </li> <?php endwhile; ?> <?php else : ?> <?php endif; ?> </ul>
2017年はこれでうまくいっていたのですが、
2018/02/02
など、来年のものがうまく表示されません。
どこがおかしいかご教授していただけないでしょうか?
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー