在帖子页面中只显示Wordpress中最近两年的帖子
我为帖子创建了一个名为Blog的页面,在阅读设置中,我选择了Blog页面作为帖子页面。现在我想要的是我只想展示过去两年的帖子,而不是全部。我怎样才能做到这一点在帖子页面中只显示Wordpress中最近两年的帖子,wordpress,Wordpress,我为帖子创建了一个名为Blog的页面,在阅读设置中,我选择了Blog页面作为帖子页面。现在我想要的是我只想展示过去两年的帖子,而不是全部。我怎样才能做到这一点 提前感谢。以下是查询的基本代码 <?php $args = array( 'post_type' => 'post', 'posts_per_page' => -1, 'order' => 'DESC', 'orderby' => 'date',
提前感谢。以下是查询的基本代码
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'date',
'date_query' => array(
array(
'column' => 'post_date_gmt',
'before' => '2 year ago',
),
),
);
$query = new WP_Query( $args );
if($query->have_posts()): while($query->have_posts()): $query->the_post();
/*
* Your HTML styles to display the post
*/
?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
此外,请参阅以下文档以了解更多信息
希望它对你有用
谢谢