Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hey all first off im a WP newbie so go easy!

Ive been searching for a couple of days now to see if I can find the answer to this but cant get anything definitive.

I have a custom post type called 'documents' and a corresponding archive called archive-documents.php. When I click on a custom taxonomy it displays my custom posts in the default archive.php template.

Rather than trying to explain more here is the code in functions.php

add_action('init', 'documents_register');

function documents_register() {

$labels = array(
    'name' => _x('Documents', 'post type general name'),
    'singular_name' => _x('Document', 'post type singular name'),
    'add_new' => _x('Add New', 'Document Entry'),
    'add_new_item' => __('Add New Document Entry'),
    'edit_item' => __('Edit Document Entry'),
    'new_item' => __('New Document Entry'),
    'view_item' => __('View Document Entry'),
    'search_items' => __('Search Documents'),
    'not_found' =>  __('Nothing found'),
    'not_found_in_trash' => __('Nothing found in Trash'),
    'parent_item_colon' => ''
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'menu_icon' => get_stylesheet_directory_uri() . '/images/documents-icon.png',
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'rewrite' => array( 'slug' => 'documents' ),
    'has_archive' => true,
    'supports' => array('title','editor','thumbnail'),

  ); 

register_post_type( 'documents' , $args );

register_taxonomy("types", array("documents"), array("hierarchical" => true, "label" => "Types", "singular_label" => "Type", "rewrite" => true));

}

share|improve this question
2  
have you tried flushing the rewrite rules (by going to the permalinks settings page & clicking save)? also (sorry, this bit isn't an answer to your question, just me being picky!), i find it more logical to follow the convention of naming custom post types using the singular noun (as used in core for "post" & "page"). "type" is also a reserved term in WordPress so you shouldn't use that for your taxonomy. –  Simon Blackbourn Jan 27 '13 at 0:31
    
@SimonBlackbourn Thanks so much! Post this as an answer and hopefully OP will mark it as best answer –  Danger14 Jun 17 at 18:00

1 Answer 1

When you're viewing a Custom Post Type Archive, your archive-documents.php template will be used. In your case this is the URL /documents/.

When you're viewing a taxonomy term, you're viewing a Custom Taxonomy Archive, not a Custom Post Type Archive. If you haven't created one specific to your taxonomy, then archive.php (or index.php, if archive.php doesn't exist) will be used.

You want to create a template named taxonomy-types.php to display the posts in your custom taxonomy.

See the Template Hierarchy for more info.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.