1

I want to use custom post types with a custom taxonomy for different types of posts on my page. I have registered a custom post type called "portfolio" and a taxonomy for this post type.

function my_custom_post_portfolio() {
  $labels = array(
    'name'               => _x( 'Portfolio', 'post type general name' ),
    'singular_name'      => _x( 'Portfolio-item', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'portfolio' ),
    'add_new_item'       => __( 'Add New Item' ),
    'edit_item'          => __( 'Edit Item' ),
    'new_item'           => __( 'New Item' ),
    'all_items'          => __( 'All Items' ),
    'view_item'          => __( 'View Item' ),
    'search_items'       => __( 'Search Items' ),
    'not_found'          => __( 'No items found' ),
    'not_found_in_trash' => __( 'No items found in the Trash' ), 
    'parent_item_colon'  => '',
    'menu_name'          => 'Portfolio'
  );
  $args = array(
    'labels'        => $labels,
    'description'   => 'Holds our portfolio items',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
    'taxonomies'    => array('category'),      
    'has_archive'   => true,
  );
  register_post_type( 'portfolio', $args ); 
}
add_action( 'init', 'my_custom_post_portfolio' );    

function add_custom_taxonomies() {
    register_taxonomy('portfolioitems', 'portfolio', array(
        'hierarchical' => true,
        'labels' => array(
            'name' => _x( 'Portfolioitems', 'taxonomy general name' ),
            'singular_name' => _x( 'Item', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search items' ),
            'all_items' => __( 'All items' ),
            'parent_item' => __( 'Parent item' ),
            'parent_item_colon' => __( 'Parent item:' ),
            'edit_item' => __( 'Edit item' ),
            'update_item' => __( 'Update item' ),
            'add_new_item' => __( 'Add new item' ),
            'new_item_name' => __( 'New item name' ),
            'menu_name' => __( 'items' ),
        ),
        'rewrite' => array(
            'slug' => 'portfolio',
            'with_front' => false,
            'hierarchical' => true
        ),
    ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );

I have template files for both of them, a archive-portfolio.php, the "starting page" of the portfolio posts, a single-portfolio.php for the display of the single portfolio item, and a taxonomy-portfolioitems.php for displaying all posts related to one "tag" (technically a custom taxonomy item)

It is working now fine, except that I get a 404 when trying to view the portfolio post. My permalink structure is:

/%category%/%postname%/

and I have the FV Top Level Categories plugin active to remove the "category" (like /category/portfolio/portfolio-post) from the url.

When I try to view my "normal" blog posts its working fine, the url is /blog/blog-categoryname/post-name

But my custom post type items give me 404 when trying to call /custom-post-type/post-name

(I have also a menu link called "portfolio" and its pointing to the category portfolio, which is registered with the custom post type.. could this be intefering somehow?)

Thanks so much!

  • Aaah I think I found the problem. Its somehow really intefering with each other, I changed the slug of my custom taxonomy to ` 'slug' => 'portfolio-tags',`and now its working! the "tags" of the portfolio are now displayed as /portfolio-tags/tag, but thats not so bad. Why is it like this? would be great if anybody could explain, eager to learn more – Owl May 30 '14 at 7:17
  • If your are using the same name/slug WP just can't know what is wanted, the post type archive or the tag archive. – Nicolai Jun 4 '14 at 12:33
0

As you've said in your comment, the solution - in your case - was to change the slug of your custom taxonomy. The trouble you've been running into here is that you had no distinct and unique permalink structure. Namely, it has been unclear to WordPress if the slug portfolio is supposed to be the post type or tag archive, because of that it hasn't been able to chose a distinct procedure, like which template would be correct in this case, which leads to the an error like you described it.

  • thx somuch for the explanation! – Owl Jun 6 '14 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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