我做了一个ajax过滤器来过滤每年的帖子,但是这个过滤器并没有显示所有的项目。年份按DESC顺序显示,但并非所有年份都显示,我不明白。。。。
<?php $terms_year = array(
\'post_type\' => array(\'publications\'),
);
$years = array();
$query_year = new WP_Query( $terms_year );
if ( $query_year->have_posts() ) :
while ( $query_year->have_posts() ) : $query_year->the_post();
$year = get_the_date(\'Y\');
if(!in_array($year, $years)){
$years[] = $year;
}
endwhile;
wp_reset_postdata();
endif;
?>
要显示筛选器,请执行以下操作:
<ul class="d-flex js-filter px-0 pb-3 justify-content-center">
<span class="text-uppercase font-weight-bold"><?php _e( \'Year:\', TEXTDOMAIN ); ?></span>
<li class="text-center js-filter-item"><a class="" data-allr="all"><?php _e( \'All\', TEXTDOMAIN ); ?></a></li>
<?php foreach( $years as $year ) {?>
<li class="text-center js-filter-item">
<a class="" data-year="<?php echo $year;?>" ref="#"><?php echo $year;?></a>
</li>
<?php }?>
</ul>
最合适的回答,由SO网友:artist learning to code 整理而成
哈哈——我不得不在$terms\\u year查询中添加posts\\u per\\u页面。留着这个以防万一。。。
$terms_year = array(
\'post_type\' => array(\'publications\'),
\'posts_per_page\'=>-1,
);