Skip to main content

Status codes are sent in the headers of HTTP requests. Your current function is hooked into a hook that will be called too late.

You should try to hook your function rr_404_my_event() into action send_headers.

I'm not sure if at that point in time it's even possible to check the Post ID, but give this a go:

add_action( 'send_headers', 'rr_404_my_event()''rr_404_my_event' );
function rr_404_my_event()() {
    global $post;
    if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) {
        include( get_query_template( '404' ) );
        header('HTTP/1.0 404 Not Found');
        exit; # so that the normal page isn't loaded after the 404 page
    }
}

Status codes are sent in the headers of HTTP requests. Your current function is hooked into a hook that will be called too late.

You should try to hook your function rr_404_my_event() into action send_headers.

I'm not sure if at that point in time it's even possible to check the Post ID, but give this a go:

add_action( 'send_headers', 'rr_404_my_event()' );
function rr_404_my_event()() {
    global $post;
    if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) {
        include( get_query_template( '404' ) );
        header('HTTP/1.0 404 Not Found');
        exit; # so that the normal page isn't loaded after the 404 page
    }
}

Status codes are sent in the headers of HTTP requests. Your current function is hooked into a hook that will be called too late.

You should try to hook your function rr_404_my_event() into action send_headers.

I'm not sure if at that point in time it's even possible to check the Post ID, but give this a go:

add_action( 'send_headers', 'rr_404_my_event' );
function rr_404_my_event() {
    global $post;
    if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) {
        include( get_query_template( '404' ) );
        header('HTTP/1.0 404 Not Found');
        exit; 
    }
}
Source Link
Marc Dingena
  • 1.1k
  • 1
  • 10
  • 22

Status codes are sent in the headers of HTTP requests. Your current function is hooked into a hook that will be called too late.

You should try to hook your function rr_404_my_event() into action send_headers.

I'm not sure if at that point in time it's even possible to check the Post ID, but give this a go:

add_action( 'send_headers', 'rr_404_my_event()' );
function rr_404_my_event()() {
    global $post;
    if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) {
        include( get_query_template( '404' ) );
        header('HTTP/1.0 404 Not Found');
        exit; # so that the normal page isn't loaded after the 404 page
    }
}