1

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

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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