I'm driving myself crazy with the following issue, hope you can help me!

I'm working on a WordPress theme for a business directory so I decided to make some custom posts types on functions.php file like "Surgical", "Non Surgical", etc... Under the custom post type of "surgical" I've created a custom taxonomy called "surgical_cat". Everything is ok until now.

The thing is that I've created some categories under "surgical_cat" called "Arm Lift", "Brachioplasty reduction", “Breast Augmentation” and I made template according to the codex rule: http://codex.wordpress.org/Category_Templates but it didn't work. I have been looking around like crazy and nothing showed up... except 404.php error page/template.

Can someone please let me know how to proceed to make this category based template for my category inside this custom taxonomy? I am really worried about this :( Thank you very much!

To see the site, please visit that link: http://my-portfolio-site.site88.net/business_directory/

You could find the list under the title: Procedures Surgical

CUSTOM POST TYPE REGISTERING FOR 'surgical' on functions.php file:

add_action( 'init', 'surgical_post' );
function surgical_post() {
        register_post_type( 'surgical',
                'labels' => array(
                        'name' => __( 'Surgical' ),
                        'singular_name' => __( 'Surgical' ),
                        'add_new' => __( 'Add New' ),
                        'add_new_item' => __( 'Add New Surgical' ),
                        'edit_item' => __( 'Edit Surgical' ),
                        'new_item' => __( 'New Surgical' ),
                        'view_item' => __( 'View Surgical' ),
                        'not_found' => __( 'Sorry, we couldn\'t find the Surgical you are looking for.' )
                'public' => true,
                'publicly_queryable' => true,
                'exclude_from_search' => true,
                'menu_position' => 5,
                'has_archive' => true,
                'hierarchical' => false,
                'capability_type' => 'page',
                'rewrite' => array( 'slug' => 'surgical' ),
                'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail', )


add_action( 'init', 'business_listing_taxonomy');
function business_listing_taxonomy() {
        'surgical_cat',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
        'surgical',  //post type name
        'public'                => true,
        'hierarchical'          => true,
        'label'                 => 'Surgical Category',  //Display name
        'query_var'             => true,
        'show_admin_column' => true,
        'rewrite'               => array(
            'slug'              => 'surgical', // This controls the base slug that will display before each term
            'with_front'        => false // Don't display the category base before

wp list categories for displaying categories on homepage:

    //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
$args = array(
  'post_type'     => 'surgical',
  'taxonomy'     => 'surgical_cat',
  'orderby'      => 'surgical_order',
  'show_count'   => 1,
  'pad_counts'   => 1,
  'hierarchical' => 1,
  'title_li'     => '',
<?php wp_list_categories( $args ); ?>
  • What do you mean about this statement, "I need these categories to have an specific look, different than the index or category template and I can't make it."? Jan 22, 2015 at 9:03

1 Answer 1


You should create a taxonomy template, not a category. I suspect that you have misunderstanding about categories, terms and custom taxonomies. I would suggest that you read my post on this particular subject here

Study the taxonomy template hierarchy in the linked page in your question

As for the 404 page, you most probably haven't flushed your permalinks after adding your custom post type.


I have missed the fact that your rewrites for both your custom post type and taxonomy is the same, which will 404 all taxonomy requests. Have a look at this recent post, it has a work around if you want to keep your slugs the same.

Here is the solution reposted by @JeremyLove. Change the code as needed and with your taxonomy and post type names. Also, important, flush your permalinks after making any changes to your code so that the new structures can be saved

function taxonomy_slug_rewrite($wp_rewrite) {
    $rules = array();
    // get all custom taxonomies
    $taxonomies = get_taxonomies(array('_builtin' => false), 'objects');
    // get all custom post types
    $post_types = get_post_types(array('public' => true, '_builtin' => false), 'objects');

    foreach ($post_types as $post_type) {
        foreach ($taxonomies as $taxonomy) {

            // go through all post types which this taxonomy is assigned to
            foreach ($taxonomy->object_type as $object_type) {

                // check if taxonomy is registered for this custom type
                if ($object_type == $post_type->rewrite['slug']) {

                    // get category objects
                    $terms = get_categories(array('type' => $object_type, 'taxonomy' => $taxonomy->name, 'hide_empty' => 0));

                    // make rules
                    foreach ($terms as $term) {
                        $rules[$object_type . '/' . $term->slug . '/?$'] = 'index.php?' . $term->taxonomy . '=' . $term->slug;
    // merge with global rules
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
add_filter('generate_rewrite_rules', 'taxonomy_slug_rewrite');
  • Hi @Pieter Goosen, thanks for your reply. According to your advice, I have created a template called taxonomy-surgical_cat-arm-lift.php where surgical_cat is custom taxonomy for post and arm-lift is term of that custom taxonomy. Then I flushed my permalinks after adding my custom post type using that code flush rules on theme activation, but still it doesn't work. Do you have any advice? Keep well. Jan 26, 2015 at 3:38
  • Please see my update, this should solve your issue Jan 26, 2015 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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