I have a custom post type that uses the main single page only on specific terms, but others really don't need the single. I want to avoid a user accessing the permalink for all of the terms but one. I imagine there must be a way to "extend" the main custom post type rule to be used only on specific terms but not sure. I guess there's no "official" wordpress way of doing it but maybe using custom functions? Any clues?
1 Answer
ok - so this isn't what I wanted but it does the trick. Adding a function to redirect when the user hits any term but one:
function my_page_template_redirect() {
if( is_singular( 'custom-post-type' ) && !(has_term('term', 'custom-taxonomy')) ) {
wp_redirect( home_url(), 301 );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
Answer based on this one: Disable Single Post View for Specific Taxonomy on Custom Post Type