0

I'm working on a site and am using Custom Post Types, Custom Taxonomies and Custom Terms for the first time. All goes well until I click a custom term. What I'd like to happen is get a page listing all posts associated with that term. Instead, all I get is my 404-page.

In detail: I have created a CPT called 'olien', a Custom Taxonomy called 'oil_chemfam' (slug: 'familie') and a Custom Term called 'ethers'. I can list all posts for this CPT, including custom taxonomies and terms.

The main CPT page /olien correctly lists all posts for the CPT 'olien', using the template /template-parts/content-olien.php.

To list all posts associated with the term 'ethers' I created a template 'taxonomy-olien-oil_chemfam.php'. I also tried archive-olien-oil_chemfam.php and /template/parts/content-olien-oil_chemfam.php. Unfortunately the only result I get is the 404-page.

I have read the following pages:

I manually registered the CPT 'olien' like this:

function custom_post_type() {
    $labels = array(
        'name'                => _x( 'Oliën', 'Post Type General Name', 'gardener' ),
        'singular_name'       => _x( 'Olie', 'Post Type Singular Name', 'gardener' ),
        'menu_name'           => __( 'Oliën', 'gardener' ),
        'all_items'           => __( 'Alle Oliën', 'gardener' ),
        'view_item'           => __( 'Bekijk de Olie', 'gardener' ),
        'add_new_item'        => __( 'Voeg een nieuwe Olie toe', 'gardener' ),
        'add_new'             => __( 'Voeg een nieuwe Olie toe', 'gardener' ),
        'edit_item'           => __( 'Bewerk de Olie', 'gardener' ),
        'update_item'         => __( 'Update de Olie', 'gardener' ),
        'search_items'        => __( 'Zoek een Olie', 'gardener' ),
        'not_found'           => __( 'Niet Gevonden', 'gardener' ),
        'not_found_in_trash'  => __( 'Niet Gevonden in Prullenbak', 'gardener' ),
    );
    $args = array(
        'label'               => __( 'olien', 'gardener' ),
        'description'         => __( 'Essentiële Oliën en Eigenschappen', 'gardener' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', ),
        'taxonomies'          => array( 'oil_note', 'oil_chemfam', 'oil_theraprop' ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 4,
        'menu_icon'           => 'dashicons-palmtree',
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
    );
    register_post_type( 'olien', $args );
}

and the Custom Taxonomy like this:

function ta_oil_chemfam() {

    $labels = array(
        'name'                       => _x( 'Chemische Families', 'Taxonomy General Name', 'gardener' ),
        'singular_name'              => _x( 'Chemische Familie', 'Taxonomy Singular Name', 'gardener' ),
        'menu_name'                  => __( 'Chemische Familie', 'gardener' ),
        'all_items'                  => __( 'Alle Chemische Families', 'gardener' ),
        'parent_item'                => null, //__( 'Bovenliggend item', 'gardener' ),
        'parent_item_colon'          => null, //__( 'Bovenliggend item:', 'gardener' ),
        'new_item_name'              => __( 'Nieuwe Chemische Familie', 'gardener' ),
        'add_new_item'               => __( 'Voeg een Chemische Familie toe', 'gardener' ),
        'edit_item'                  => __( 'Bewerk Chemische Familie', 'gardener' ),
        'update_item'                => __( 'Update Chemische Familie', 'gardener' ),
        'view_item'                  => __( 'Bekijk Chemische Familie', 'gardener' ),
        'separate_items_with_commas' => __( 'Scheid meerdere Chemische Families met een komma', 'gardener' ),
        'add_or_remove_items'        => __( 'Voeg toe of verwijder', 'gardener' ),
        'choose_from_most_used'      => __( 'Kies uit de meeste gebruikte', 'gardener' ),
        'most_used'                  => null,
        'popular_items'              => __( 'Meest voorkomende Chemische Families', 'gardener' ),
        'search_items'               => __( 'Zoek een Chemische Familie', 'gardener' ),
        'not_found'                  => __( 'Niet gevonden', 'gardener' ),
        'no_terms'                   => __( 'Geen Chemische Families', 'gardener' ),
        'items_list'                 => __( 'Lijst met Chemische Families', 'gardener' ),
        'items_list_navigation'      => __( 'Blader door Chemische Families', 'gardener' ),
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => false,
        'has_archive'                => true,
        'meta_box_cb'                => 'post_categories_meta_box', // adds checkboxes
        'rewrite'                    => array(
                                     'slug' => 'familie'
        )
    );
    register_taxonomy( 'oil_chemfam', array( 'olien' ), $args );

}
add_action( 'init', 'ta_oil_chemfam', 10 );

Thanks for any and all suggestions!

  • 404s have nothing to do with templates, WordPress decides a request is a 404 long before the template is loaded. Have you flushed rewrite rules after adding the post type and taxonomy? – Milo May 2 '18 at 15:39
  • Thank you Milo! That worked. I must have missed that somewhere and would have never thought of it myself. Is this like emptying cache memory? – Guido May 2 '18 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.