尝试此功能,将获取今天之前“$天”的所有帖子
/*
* Get all posts from a specific day
*
* $day = how many days before today
*
* usage: posts_from_the_day() will show posts from today
* posts_from_the_day(1) will show posts from yesterday
* posts_from_the_day(30) will show posts from 30 days ago
*
*/
function posts_from_the_day( $day = 0 ) {
$now = date(\'U\'); //Get current second time
$desired = $now - ( $day * 86400 ); //86400 = seconds in a day
$year = date(\'Y\', $desired);
$month = date(\'m\', $desired);
$day = date(\'n\', $desired);
$query = new WP_Query( array(
\'year\' => $year,
\'monthnum\' => $month,
\'day\' => $day,
\'posts_per_page\' => -1,
);
if ($query->have_posts() ) {
echo \'<h3>\'. date(\'L, F d, Y\', $desired) . \' (\'. $query->found_posts .\') </h3>\';
while ( $query->have_posts() ) {
$query->the_post();
//do something
}
}
}