Disable Single Post View for Specific Taxonomy on Custom Post Type

I use template_redirect hook for this purpose. I suppose rented in your question is not taxonomy itself, but one term of some taxonomy.

function my_page_template_redirect() {
    if( is_singular( 'rentals' ) && has_term('rented', 'your taxonomy name') ) {
        wp_redirect( home_url(), 301 );
        exit();
    }
}
add_action( 'template_redirect', 'my_page_template_redirect' );

Before page rendering, WP checks if CPT rentals single post is viewed, and if it has rented term … and if so, it will redirect visitor somewhere else.

Leave a Comment