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 was hoping someone could help me. I have done some serious googling but cannot find the answer for this one.

I have a custom post type called tutorials.

I can go to mysite.com/tutorials and get a list of all the tutorials.

I have also created a custom taxonomy called tutorial_categories with the following code:

register_taxonomy(
        'tutorial_categories',
        'tutorials',
        array(
            'labels' => array(
                'name' => 'Tutorial Categories',
                'add_new_item' => 'Add New Tutorial Category',
                'new_item_name' => "New Tutorial Category"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true,
            'hasArchive' => true
        )
    );

How can I create a category page for a tutorial_category, so if someone goes to:

mysite.com/tutorials/php/

They will get a list of tutorials (custom post type) with the custom taxonomy of PHP.

A member of stackoverflow recommended I take a look at this:

But this doesn't work either. I have created the taxonomy-tutorial_categories.php page but I still get page not found.

share|improve this question
    

1 Answer 1

up vote 2 down vote accepted

You are doing everything right, double check the below code and make sure to go to Permalinks in your dashboard to flush the rewrite rules.

From Wordpress Codex:

Note: Visiting the Permalinks screen triggers a flush of rewrite rules. There is no need to save just to flush the rewrite rules.

It will work, I tested it using the below code:

Put the following in your functions.php:

add_action( 'init', 'create_custom_posts' );
function create_custom_posts ()
{      
    register_post_type( 'tutorials',
        array(
            'labels' => array(
                'name' => __( 'Tutorials' ),
                'singular_name' => __( 'Tutorial' )
            ),
        'public' => true,
        'supports' => array ('title', 'editor', 'thumbnail')
        )
    );

    register_taxonomy(
        'tutorial_categories',
        'tutorials',
        array(
            'labels' => array(
                'name' => 'Tutorial Categories',
                'add_new_item' => 'Add New Tutorial Category',
                'new_item_name' => "New Tutorial Category"
            ),
            'show_ui' => true,
            'show_tagcloud' => false,
            'hierarchical' => true,
            'hasArchive' => true
        )
    );
}

Create taxonomy-tutorial_categories.php, add a taxonomy category called php from the dashboard, and visit {yourwebsite.com}/tutorial_categories/php/. Works like a charm.

share|improve this answer
1  
Thank you! I think mostly I was going to the wrong URL. This works a treat, thank you for your fast support! –  Leon Revill Oct 4 '13 at 6:32
    
Sure thing. Exactly, you don't go to {custom_post_type}/category. It's {taxonomy}/category. –  P-S Oct 4 '13 at 6:50

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.