I’ve a web site with a customized publish sort for “Personnel”. When a Personnel publish is drafted, I would prefer to redirect the consumer to a customized notification web page moderately than a 404. I’ve tried the next, tailored from this SO thread, which works solely when logged in, however nonetheless sends to a 404 web page when not logged in- is there a method I can get this to work for all customers? It appears WordPress’s default 404 conduct is intercepting the request for basic web site customers as an alternative of utilizing this template_redirect
hook. Maybe there’s a completely different option to go about this? Thanks for any perception right here.
add_action( 'template_redirect', 'inactive_personnel_redirect' );
perform inactive_personnel_redirect() {
world $publish;
if( ( $post->post_status == 'draft' ) && ( is_singular('personnel') ) ) {
wp_redirect( home_url() . '/employees/inactive-notification/', 301 );
exit;
}
}