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 am experiencing problems with custom post types, taxonomies, permalinks and rewrites.

I created a custom "recipes" post type and taxonomy using this code:

add_action('init', 'recipes_register');
function recipes_register() {
$labels = array(
 'name' => __('Recipes', 'framework'),
 'singular_name' => __('Recipe', 'framework'),
 'add_new' => __('Add Recipe', 'framework'),
 'add_new_item' => __('Add New Recipe', 'framework'),
 'edit_item' => __('Edit Recipe', 'framework'),
 'new_item' => __('New Recipe', 'framework'),
 'view_item' => __('View Recipe', 'framework'),
 'search_items' => __('Search Recipe', 'framework'),
 'not_found' =>  __('Nothing found', 'framework'),
 'not_found_in_trash' => __('Nothing found in Trash', 'framework'),
 'parent_item_colon' => ''
);
$args = array(
 'labels' => $labels,
 'public' => true,
 'publicly_queryable' => true,
 'show_ui' => true,
 'query_var' => true,
 'menu_icon' => get_stylesheet_directory_uri() . '/img/admin-recipes.png',
 'rewrite' => true,
 'capability_type' => 'post',
 'hierarchical' => true,
 'menu_position' => null,
 'supports' => array('title','editor','thumbnail','comments'),
  ); 
register_post_type( 'recipes' , $args );
}

register_taxonomy('recipe_type', array('recipes'), array('hierarchical' => true, 'label' => __('Recipe Type', 'framework'), 'rewrite' => array('hierarchical' => true, 'slug'=>'recipes')));

The problem occurs when I want to access to custom type post with this type of URL, it throws a 404 error :

http://my-website/recipes/name-of-the-recipe/

I think the problem is caused because I want to use the same slug for the taxonomy "recipe_type" and the "recipe" custom post type.

I am a bit stuck on this and I would be grateful if you could help me with this.

Thanks

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

your custom post type will likely work if you visit your permalinks page and save, which forces a flush of the rewrite rules. however, you probably won't be able to get the taxonomy to work using the same slug, custom post types seem to supersede taxonomies if they share a slug. anyway, it would probably be a big performance hit even if it did work, WP would have to generate a rewrite rule for every term or post you create, or look in two different places for every request.

also- your register_taxonomy should be wrapped in a function that gets called on init, like your recipes_register function.

share|improve this answer
add comment

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.