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.

I have registered a custom post type in my functions.php file for "Wines", with this code:

function customposttype_wines() {

$labels = array(
    'name'                => 'Wines',
    'singular_name'       => 'Wine',
    'menu_name'           => 'Wines',
    'parent_item_colon'   => 'Parent Wine',
    'all_items'           => 'All Wines',
    'view_item'           => 'View Wine',
    'add_new_item'        => 'Add New Wine',
    'add_new'             => '+',
    'edit_item'           => 'Edit Wine',
    'update_item'         => 'Update Wine',
    'search_items'        => 'Search Wines',
    'not_found'           => 'No Wines found',
    'not_found_in_trash'  => 'No Wines found in Trash',
);
$args = array(
    'label'               => 'wines',
    'description'         => 'Wine Reviews',
    'labels'              => $labels,
    'supports'            => array( 'title', ),
    'unset'            => array ('date'),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'post',
);
register_post_type( 
                'wines',
                $args 
                );

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

And registered 9 custom taxonomies (brand, region, grape, etc.) with this code (repeated 9 times with only the <XXX> changing for each):

function customtaxonomy_<XXX> ()  {

$labels = array(
    'name'                       => '<XXX>',
    'singular_name'              => '<XXX>',
    'menu_name'                  => '<XXX>s',
    'all_items'                  => 'All <XXX>s',
    'parent_item'                => 'Parent <XXX>',
    'parent_item_colon'          => 'Parent <XXX>:',
    'new_item_name'              => 'New <XXX> Name',
    'add_new_item'               => 'Add New <XXX>',
    'edit_item'                  => 'Edit <XXX>',
    'update_item'                => 'Update <XXX>',
    'separate_items_with_commas' => 'Separate <XXX>s w/commas',
    'search_items'               => 'Search <XXX>s',
    'add_or_remove_items'        => 'Add or Remove <XXX>s',
    'choose_from_most_used'      => 'Choose from the most used <XXX>s',
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
    'query_var'                  => true,
);
register_taxonomy( 
    '<XXX>s',
    'wines',
    $args 
);
}
add_action( 'init', 'customtaxonomy_<XXX>', 0 );

Now I am trying to display the lists of custom taxonomy terms on the parent page of each, so when visiting www.mywebsite.com/wines/<XXX> there is a list, with links, to all the terms that have been entered.

Right now when I visit www.mywebsite.com/wines/<XXX> I just see the 404.php error page. But if I visit a taxonomy term page I see the posts within there fine, ie: www.mywebsite.com/wines/<XXX>/term

I tried using a taxonomy template hierarchy page, taxonomy-<XXX>.php but it will not load, still just shows the 404.php.

Pulling hair here, any help is very appreciated.

share|improve this question
    
Just for a moment - Rereading question... you going to show a what? category page of non category? (just for a moment try to remamber a /category or /tags url in any of WordPress sites you ever visit/create)... (i am not talking that this imposible)... its just require a custom solution with rewrite urls/query vars/template filter. Let us know if question still active... –  Oleg Butuzov Oct 30 '13 at 19:39
    
Thank you for your reply, Oleg. I was not able to find a solution to do it the way I wanted/thought I could. I will update the question with my answer for how I did it and mark as solved. –  codeview Oct 31 '13 at 22:54

3 Answers 3

Read more carefully about register_taxonomy, you will notice that you forgot a rewrite argument, that anables pretty links (rewrites + links generation) for your taxonomy. As for listing taxonomies you can use wp_list_categories or any other alternatives.

share|improve this answer
    
Thank you for the reply, but I did think of that and had read through. The rewrite argument is set to "true" by default and the slug is set to "$taxonomy" by default, so wouldn't I not need to include this if I would just be using those same settings? –  codeview Oct 28 '13 at 21:26
    
Correct, if not explicitly stated, the rewrite defaults to the taxonomy name. –  helgatheviking Oct 28 '13 at 22:01

If you are getting a 404 you might need to re-save your permalinks.

If you want all the taxonomies to display the same and you don't have any other custom taxonomies to worry about you could just work in the taxonomy.php template. If you do have other taxonomies you could instruct WP to use the same template for all these taxonomies via the template_include filter.

function wpa_120317_template_include($template) {
        $taxonomies = array( 'XXX', 'YYY', 'ZZZ' );
    if ( is_tax( $taxonomies ) ){
        $template = get_stylesheet_directory() . '/custom-taxonomy-for-wines.php';
    }
    return $template;
}
add_filter( 'template_include', 'wpa_120317_template_include' );

And then on this custom-taxonomy-for-wines.php template you could include the following code, which would display a list of links to all the terms in that archive.

$obj = get_queried_object();
if( isset($obj->taxonomy)){
    $terms = get_terms( $obj->taxonomy );
    if ( $terms && ! is_wp_error( $terms ) ){
        echo '<ul class="term-list">';
        foreach( $terms as $term ){
            printf( '<li><a href="%s" title="%s">%s</a></li>', get_term_link( $term ), esc_attr( __('Link to ') . $term->name ), $term->name );
        }
        echo '</ul>';
    }
}
share|improve this answer
    
Thank you for your reply. I have visited the Permalinks settings page and resaved to "flush the rewrite rules" but still the 404.php loads. I implemented your code and it loads the list of the terms BUT on the term links...so if I visit mywebsite.com/wines/grapes/malbec/ there is a list of all the terms under the grapes taxonomy, including "malbec". I need the list to be one level above, at mywebsite.com/wines/grapes/ –  codeview Oct 28 '13 at 21:47
    
If you are still getting 404s, I'm stumped and would suggest going into debug-mode... switching to default theme, disabling all plugins, etc. Also check your .htaccess. As far as your other issue, I'm a little unclear what you are saying. WP doesn't create a page at mywebsite.com/wines/sometaxonomy so I don't know what to suggest. Also verify you don't have any pages with the same slugs. –  helgatheviking Oct 28 '13 at 22:09
up vote 0 down vote accepted

I was not able to find a solution for doing it the way I was wanting/thinking I could. So...decided to name the taxonomies the singular name (ie: brand, grape, region) and then create pages with the plural of the same name (ie: brands, grapes, regions) and on each page I will have to use the get_terms function for a specific taxonomy to be able to have links to each term created under each taxonomy. But now I can't get get_terms to work. Ugh!

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.