admin管理员组

文章数量:1130349

I have a custom taxonomy, "type", which is 'hierarchical' => true,.

Terms include:

  • "Industry moves"
  • "Market indicators"
  • "Viewpoints"
    • "Analyst view"
    • "Executive view"
    • "Interview"

I have a taxonomy.php theme file and I want these pages to be accessible at

(parent term) but also eg.

(sub-terms)

I have a $rewrite. When I set 'hierarchical' => false, of course, I can only access those sub-terms at their single-level URLs eg.

When I flip it to 'hierarchical' => true, I can successfully access the page at the nested URL structure

But (and here is the problem), this messes up the page for the parent term. Specifically, then generates a 404 (actually, points back to index).

How can I both have my cake and eat it - that is, how can I access a page for both sub-terms and their parent term?

At each step, I have saved permalinks in the admin.

Here is the code I am using to register the taxonomy in a plugin...

<?php
/**
 * ==============================================================================
 *                      REGISTER TAXONOMY
 * ==============================================================================
 */

if ( ! function_exists( 'register_taxonomy_type' ) ) {

function register_taxonomy_type() {

  $labels = array(
        'name'                       => _x( 'Types', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Type', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Types', 'text_domain' ),
        'all_items'                  => __( 'All Types', 'text_domain' ),
        'parent_item'                => __( 'Parent Type', 'text_domain' ),
        'parent_item_colon'          => __( 'Parent Type:', 'text_domain' ),
        'new_item_name'              => __( 'New Type Name', 'text_domain' ),
        'add_new_item'               => __( 'Add New Type', 'text_domain' ),
        'edit_item'                  => __( 'Edit Type', 'text_domain' ),
        'update_item'                => __( 'Update Type', 'text_domain' ),
        'view_item'                  => __( 'View Type', 'text_domain' ),
        'separate_items_with_commas' => __( 'Separate Types with commas', 'text_domain' ),
        'add_or_remove_items'        => __( 'Add or remove Type', 'text_domain' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
        'popular_items'              => __( 'Popular Type', 'text_domain' ),
        'search_items'               => __( 'Search Type', 'text_domain' ),
        'not_found'                  => __( 'Not Found', 'text_domain' ),
        'no_terms'                   => __( 'No Type', 'text_domain' ),
        'items_list'                 => __( 'Types list', 'text_domain' ),
        'items_list_navigation'      => __( 'Types list navigation', 'text_domain' ),
        );
    $rewrite = array(
        'slug'                       => 'type',
        'with_front'                 => true,
        'hierarchical'               => false,
    );
        $args = array(
            'labels'                     => $labels, // as above
            'public'                     => true,
            'show_ui'                    => true,
            'show_in_nav_menus'          => true,
            'hierarchical'               => true,
            'show_admin_column'          => true,
        'single_value'               => false, // Use single-select radio button, only one Type per object
            'show_tagcloud'              => true,
            'rewrite'                    => $rewrite,// as above
        );
    // Put it all together!
    register_taxonomy(
        /* taxonomy name */         'type',
        /* attach to object */  array( 'article' ),
        /* arguments */                 $args
    );

}
add_action( 'init', 'register_taxonomy_type', 0 );

}
?>

I have a custom taxonomy, "type", which is 'hierarchical' => true,.

Terms include:

  • "Industry moves"
  • "Market indicators"
  • "Viewpoints"
    • "Analyst view"
    • "Executive view"
    • "Interview"

I have a taxonomy.php theme file and I want these pages to be accessible at

(parent term) but also eg.

(sub-terms)

I have a $rewrite. When I set 'hierarchical' => false, of course, I can only access those sub-terms at their single-level URLs eg.

When I flip it to 'hierarchical' => true, I can successfully access the page at the nested URL structure

But (and here is the problem), this messes up the page for the parent term. Specifically, then generates a 404 (actually, points back to index).

How can I both have my cake and eat it - that is, how can I access a page for both sub-terms and their parent term?

At each step, I have saved permalinks in the admin.

Here is the code I am using to register the taxonomy in a plugin...

<?php
/**
 * ==============================================================================
 *                      REGISTER TAXONOMY
 * ==============================================================================
 */

if ( ! function_exists( 'register_taxonomy_type' ) ) {

function register_taxonomy_type() {

  $labels = array(
        'name'                       => _x( 'Types', 'Taxonomy General Name', 'text_domain' ),
        'singular_name'              => _x( 'Type', 'Taxonomy Singular Name', 'text_domain' ),
        'menu_name'                  => __( 'Types', 'text_domain' ),
        'all_items'                  => __( 'All Types', 'text_domain' ),
        'parent_item'                => __( 'Parent Type', 'text_domain' ),
        'parent_item_colon'          => __( 'Parent Type:', 'text_domain' ),
        'new_item_name'              => __( 'New Type Name', 'text_domain' ),
        'add_new_item'               => __( 'Add New Type', 'text_domain' ),
        'edit_item'                  => __( 'Edit Type', 'text_domain' ),
        'update_item'                => __( 'Update Type', 'text_domain' ),
        'view_item'                  => __( 'View Type', 'text_domain' ),
        'separate_items_with_commas' => __( 'Separate Types with commas', 'text_domain' ),
        'add_or_remove_items'        => __( 'Add or remove Type', 'text_domain' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
        'popular_items'              => __( 'Popular Type', 'text_domain' ),
        'search_items'               => __( 'Search Type', 'text_domain' ),
        'not_found'                  => __( 'Not Found', 'text_domain' ),
        'no_terms'                   => __( 'No Type', 'text_domain' ),
        'items_list'                 => __( 'Types list', 'text_domain' ),
        'items_list_navigation'      => __( 'Types list navigation', 'text_domain' ),
        );
    $rewrite = array(
        'slug'                       => 'type',
        'with_front'                 => true,
        'hierarchical'               => false,
    );
        $args = array(
            'labels'                     => $labels, // as above
            'public'                     => true,
            'show_ui'                    => true,
            'show_in_nav_menus'          => true,
            'hierarchical'               => true,
            'show_admin_column'          => true,
        'single_value'               => false, // Use single-select radio button, only one Type per object
            'show_tagcloud'              => true,
            'rewrite'                    => $rewrite,// as above
        );
    // Put it all together!
    register_taxonomy(
        /* taxonomy name */         'type',
        /* attach to object */  array( 'article' ),
        /* arguments */                 $args
    );

}
add_action( 'init', 'register_taxonomy_type', 0 );

}
?>

本文标签: permalinksWhy does page for hierarchical taxonomy parent term go 404