custom post types - Is there a way to use 'publicly_queryable' => false only on specific taxonomy term?

admin2025-01-07  3

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?

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?

Share Improve this question asked Jun 1, 2021 at 12:58 artist learning to codeartist learning to code 3311 gold badge5 silver badges18 bronze badges 1
  • Related: wordpress.stackexchange.com/questions/327666/… – Jesse Nickles Commented Jun 5, 2024 at 17:03
Add a comment  | 

1 Answer 1

Reset to default 0

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736260592a675.html

最新回复(0)