嘿,我试图在日期页中显示未来的帖子,但日期页重定向到404页,因为它是未来的日期,所以我使用了这个函数
function dg_override_404() {
global $wp_query, $post;
if(is_year() || is_day()){
$wp_query->is_404 = true;
}
if($wp_query->post_count == 0){
$dayarchive = get_query_var(\'day\');
$monthnumarchive = get_query_var( \'monthnum\' );
$yeararchive = get_query_var( \'year\' );
if ( $dayarchive || $monthnumarchive){
status_header( 200 );
$id=-28;
$post = new stdClass();
$post->ID= $id;
$post->post_content=\'\';
$post->post_excerpt= \'\';
$post->post_status=\'publish\';
$post->post_title= \'\';
$post->post_type=\'post\';
$post->post_date = $yeararchive.\'-\'.$monthnumarchive.\'-\'.$dayarchive.\'00:00:00\';
$wp_query->queried_object=$post;
$wp_query->post=$post;
$wp_query->found_posts = 1;
$wp_query->post_count = 1;
$wp_query->is_404 = false;
$wp_query->posts = array($post);
$wp_query->is_date = 1;
}
}
}add_filter(\'template_redirect\', \'dg_override_404\');
它可以工作,但不会在浏览器中显示页面标题,如果我更改了$wp\\U查询->is\\U日期=1;至$wp\\U查询->is\\U存档=1;工作刚刚好,但我需要在日期页中使用它,所以无论如何都有这样做,谢谢