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!