Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在帖子页面中只显示Wordpress中最近两年的帖子_Wordpress - Fatal编程技术网

在帖子页面中只显示Wordpress中最近两年的帖子

在帖子页面中只显示Wordpress中最近两年的帖子,wordpress,Wordpress,我为帖子创建了一个名为Blog的页面,在阅读设置中,我选择了Blog页面作为帖子页面。现在我想要的是我只想展示过去两年的帖子,而不是全部。我怎样才能做到这一点 提前感谢。以下是查询的基本代码 <?php $args = array( 'post_type' => 'post', 'posts_per_page' => -1, 'order' => 'DESC', 'orderby' => 'date',

我为帖子创建了一个名为Blog的页面,在阅读设置中,我选择了Blog页面作为帖子页面。现在我想要的是我只想展示过去两年的帖子,而不是全部。我怎样才能做到这一点


提前感谢。

以下是查询的基本代码

<?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;
?>

此外,请参阅以下文档以了解更多信息

希望它对你有用

谢谢