WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

so I have this custom post type and taxonomy which i set the rewrite to books because I want the URL to the specific book to be http://domain.com/books/booktitle

So this is what I have so far:

$args = array(
  'labels' => $labels,
  'public' => true,
  'publicly_queryable' => true,
  'exclude_from_search' => false,
  'show_ui' => true, 
  'show_in_nav_menus' => true,
  'query_var' => true,
  'show_in_admin_bar' => false,
  'capability_type' => 'post',
  'has_archive' => true, 
  'hierarchical' => false,
  'menu_icon' => get_template_directory_uri() . '/images/books16x16.png',
  'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
  'rewrite' => array( 'slug' => __( 'books', 'xxr' ) ),
  'taxonomies' => array( 'book-cats' )
register_post_type( 'books', $args );

register_taxonomy( 'book-cats', 
    array( 'books' ), 
    array(  'hierarchical' => false, 
    'labels' => $labels, 
    'query_var' => true ) 

Ok so the CPT works and everything is ok in the backend. However in the front end, I am not able to go to the specific book that I created. For example, I created a book title Nomo, so I type http://domain.com/books/nomo but it goes to page not found.

An even more strange finding is I have a custom query that pulls all the CPT on my homepage and it does show everything just fine. But if you however over the book link, it gives a URL of http://domain.com/uncategorized/nomo ??? I am puzzled...Why would it say uncategorized when a category is set for this?

My permalinks are set to /%category%/%postname%/ if that means anything and yes I have refreshed the permalinks already and still same issue.

NOTE: It used to work...not sure what happened...

Any help appreciated.

share|improve this question
Try taking out the 'taxonomies' element in the arguments you pass to register_post_type -- since you pass your custom post type to register_taxonomy this isn't necessary, and may be causing a problem because the taxonomy isn't declared when you call register_post_type. Also, I highly recommend the Monkeyman Rewrite Analyzer (wordpress.org/extend/plugins/monkeyman-rewrite-analyzer) for debugging rewrite problems. – Chris Carson Nov 17 '12 at 18:47
I tried taking it out but didn't make any different, my links are still pointing to "uncategorized" and typing it directly in the URL doesn't work either, it just goes back to the homepage. I presume, it can't find anything thus default to index.php. Thx for answering. – user23654 Nov 17 '12 at 18:53
up vote 0 down vote accepted

I believe you have a problem with the arrays you're passing to register_taxonomy. You have:

     array( 'books' ), 
        'hierarchical' => false, 
        'label' => __( 'Book Categories', 'sp-theme' ), 
        'singular_label' => __( 'Book Category', 'xxr' ), 
        'query_var' => true 

It should be something like...

     array( 'books' ), 
        'hierarchical' => false, 
        'labels' = array(
            'name' => _x( 'Book Categories', 'taxonomy general name' ),
            'singular_name' => _x( 'Book Category', 'taxonomy singular name' ),
            /* etc. */
        'query_var' => true 

Note that...

  • Your taxonomy name has an underscore rather than a hyphen
  • 'labels' is passed as an array rather than individual elements
share|improve this answer
Hmm they are both hyphens in my code...and I rewrote it to follow this -> codex.wordpress.org/Function_Reference/register_taxonomy but still doesn't work...The permalink of the custom post still points to "uncategorized". – user23654 Nov 17 '12 at 19:22
Ok .....i feel stupid now....the reason it didn't work is because the add action for the custom post type was wrapped inside a function that checks if it is admin...I removed the add action from there and everything started working again...I knew it used to work...hehe....thx again for your effort! Much appreciated... – user23654 Nov 17 '12 at 19:51

Your Answer


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