我需要根据条件在一些帖子上强制使用404。我成功地做到了(虽然我不知道我是否做得对),而且我的404.php
要按预期加载的模板。
My code:
function rr_404_my_event() {
global $post;
if ( is_singular( \'event\' ) && !rr_event_should_be_available( $post->ID ) ) {
include( get_query_template( \'404\' ) );
exit; # so that the normal page isn\'t loaded after the 404 page
}
}
add_action( \'template_redirect\', \'rr_404_my_event\', 1 );
代码2来自this related question - 同样的问题:function rr_404_my_event() {
global $post;
if ( is_singular( \'event\' ) && !rr_event_should_be_available( $post->ID ) ) {
global $wp_query;
$wp_query->set_404();
}
}
add_action( \'wp\', \'rr_404_my_event\' );
My Issue:
虽然看起来不错,但我得到了一个200 OK
如果我选中网络选项卡。因为这是一种状态200
, 我担心搜索引擎也会索引这些页面。Expected Behaviour:
我想要一个状态404 Not Found
待发送。