Question about template_redirect hook
-
I’m developing a multi site installation. Some of my custom post types have a permanent status of “private”. I have used the template_redirect hook like this in code snippets on each site (and varying the function name in each case) to avoid a 404 if a logged out user requests a valid URL for a private custom post:-
add_action( 'template_redirect', 'my_function_name' ); function my_function_name() { if ( is_single( 'my-custom-post-type' ) && 'private' == get_post_status( get_the_id() ) && ! is_user_logged_in() ){ $redirect = network_home_url( '/log-in/' ); wp_safe_redirect( $redirect, 301 ); exit; } }In tests, this works when the URL is for the main site. However, when the URL is for any other blog, a 404 is returned. Can anyone shed any light on this please?
Many thanks.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Question about template_redirect hook’ is closed to new replies.