要根据日期搜索帖子,可以设置WP\\u Query的快速实例。最好看的地方是official documentation, 特别是关于date parameters.
在特定月份对帖子的基本搜索看起来有点像这样:
<?php
$the_query = new WP_Query( array(
\'m\' => \'201607\', // will return posts in July 2016
\'posts_per_page\' => \'10\', // lets get only the latest 10 posts
\'post_type\' => \'post\', // you can set this to a different post type if needed
\'post_status\' => \'publish\', // \'published\' posts only, not draft/private etc.
) );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_title();
the_content();
// whatever else about the post you want to output :)
}
}
wp_reset_postdata(); // restore original post data, since custom queries modify it
?>
正如我链接到的文档中所述,您还可以使用参数
year
和
monthnum
, 甚至可以使用稍微复杂一点的
date_query
(文档中有示例)。