0
votes

I've got a question that I've seen being asked before, but none of the answers solved my problems. It's something I've run into before, but never managed to solve.

I've got a clean Wordpress installation and in the functions.php file I've created a custom post type

register_nav_menu('main', 'Main navigation menu');

function add_custom_post_type() {
    $labels = array(
        'name' => _x('Books', 'post type general name'),
        'singular_name' => _x('Book', 'post type singular name'),
        'add_new' => _x('Add New', 'book'),
        'add_new_item' => __('Add New Book'),
        'edit_item' => __('Edit Book'),
        'new_item' => __('New Book'),
        'all_items' => __('All Books'),
        'view_item' => __('View Book'),
        'search_items' => __('Search Books'),
        'not_found' =>  __('No books found'),
        'not_found_in_trash' => __('No books found in Trash'), 
        'parent_item_colon' => '',
        'menu_name' => __('Books')
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'show_in_menu' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    ); 

    register_post_type('book', $args);
}

I've made an archive-book.php and single-book.php template files for those and everything works okay. I can view the books when I go to "http://localhost/wordpress/book" Now I want to create a custom taxonomy, so I did this in functions.php as well:

add_action('init', 'add_custom_post_type');

function add_custom_taxonomy() {
    register_taxonomy(
        'rating',
        'book',
        array(
            'label' => 'Rating',
            'hierarchical' => true,
            'show_ui' => true,
            'query_var' => 'book',
            'has_archive' => true,
            'rewrite' => array(
                'slug' => 'book/rating'
            )
        )
    );
}

And the taxonomy shows up in the admin page, I can add new terms, and add them to books. But now comes the problem. I've I want to go to an overview of all books with, let's say, rating "nice", I would go to "http://localhost/wordpress/book/rating/nice". I've created the following template files: taxonomy-rating-nice.php, taxonomy-rating.php and taxonomy.php.

But somehow wordpress just shows the index.php file and doesn't list any books. I've tried flushing the rewrite rules with:

add_action('init', 'custom_taxonomy_flush_rewrite');
function custom_taxonomy_flush_rewrite() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

And:

flush_rewrite_rules(false);

But nothings seems to help.

So, anybody who can help me? If you need more information, please tell, cause I really want to fix this problem!

1
Have you tried posting on wordpress.stackexchange.com as well?Havelock

1 Answers

0
votes

1st of all go to Settings > permalinks and select your permalinks to Plain and save your settings. Then go to dashboard and view your taxonomies, then revert back your Permalink Settings to Post Name and save your permalink settings ... hope that will solve your issue ... as all your code and templates looks fine by now ... Hope that works for you