简体   繁体   中英

Taxonomy template not working for custom post type

I created a Custom post type and added a taxonomy, but the template (taxonomy.php or taxonomy-provincies.php) isn't working. All I get is a 404 error.

I already tried saving the permalink settings to help reset the permalink issue.

What am I doing wrong here?

Code for Custom post type

/* Custom post type for 'Bedrijven' */

add_action( 'init', 'custom_post_bedrijven' );
function custom_post_bedrijven() {

    $labels = array(
        'name'                  => __('Bedrijven', 'post type general name'),
        'singular_name'         => __('Bedrijf', 'post type singular name'),
        'add_new'               => __('Nieuwe bedrijf'),
        'add_new_item'          => __('Bedrijf toevoegen'),
        'edit_item'             => __('Bedrijf bewerken'),
        'new_item'              => __('Nieuwe bedrijf'),
        'all_items'             => __('Bedrijven'),
        'view_item'             => __('Bedrijven bekijken'),
        'search_items'          => __('Bedrijven zoeken'),
        'not_found'             => __('Geen bedrijven gevonden'),
        'not_found_in_trash'    => __('Geen bedrijven gevonden in archief'),
        'parent_item_colon'     => '',
        'menu_name'             => 'Bedrijven'
    );

    $supports = array (
        'title', 'editor', 'page-attributes'
    );

    $details = array (
        'labels'            => $labels,
        'label'             => 'Bedrijven',
        'capability_type'   => 'post',
        'description'       => 'Custom post type voor bedrijven',
        'public'            => true,
        'publicly_queryable'=> true,
        'show_ui'           => true, 
        'show_in_admin_bar' => true,
        'query_var'         => true,
        'hierarchical'      => true,
        'has_archive'       => true,
        'exclude_from_search' => false,
        'supports'          => $supports,
        'rewrite'           => array (
            'slug'          => 'bedrijven',
            'with_front'    => false,
        ),
        'menu_icon'         => 'dashicons-store',
        'taxonomies'        => array(
            'bedrijven_provincies'
        )
    );

    register_post_type( 'bedrijven', $details );
    flush_rewrite_rules();
}

Code for added Taxonomy

/* Custom taxonomy 'provincies' for CPT 'bedrijven' */

add_action('init', 'custom_bedrijven_provincies');
function custom_bedrijven_provincies() {

    $labels = array(
        'name'              => _x('Provincies', 'post type general name'),
        'singular_name'     => _x('Provincie', 'post type singular name'),
        'add_new'           => _x('Nieuwe provincie', 'client'),
        'add_new_item'      => __('Provincie toevoegen'),
        'edit_item'         => __('Provincie bewerken'),
        'new_item'          => __('Nieuwe provincie'),
        'view_item'         => __('Provincie bekijken'),
        'search_items'      => __('Provincie zoeken'),
        'not_found'         => __('Geen provincie gevonden'),
        'not_found_in_trash' => __('Geen provincie gevonden in archief')
    );

    $args = array(
        'labels'                => $labels,
        'hierarchical'          => true,
        'show_ui'               => true,
        'query_var'             => true,
        'show_in_nav_menus'     => true,
        'rewrite'               => array(
            'slug' => 'bedrijven_provincies',
            'with_front' => false,
        )
    );

    register_taxonomy('bedrijven_provincies', array('bedrijven'), $args);
    flush_rewrite_rules( false );
}

I think there will be the permalink issue. Please go to this path settings >> Permalinks and save this setting again.., I am sure URL will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM