0

I have a custom post type (recipes) and custom taxonomy (r_cat). To be quite honest, I'm a newbie and I've tried different scenarios and options from what I've read in various posts and google searches, but, I can't get it to do what I need.

Here is the code:

add_action('init', 'cptui_register_my_cpt_recipes');
function cptui_register_my_cpt_recipes() {
register_post_type('recipes', array(
'label' => 'Healthy Recipes',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'healthy-recipes', 'with_front' => true),
'query_var' => true,
'has_archive' => true,
'supports' => array('title','editor','custom-fields','thumbnail','page-attributes','post-formats'),
'taxonomies' => array('post_tag','r_cat'),
'labels' => array (
  'name' => 'Healthy Recipes',
  'singular_name' => 'Recipe',
  'menu_name' => 'Recipes',
  'add_new' => 'Add Recipe',
  'add_new_item' => 'Add New Recipe',
  'edit' => 'Edit',
  'edit_item' => 'Edit Recipe',
  'new_item' => 'New Recipe',
  'view' => 'View Recipe',
  'view_item' => 'View Recipe',
  'search_items' => 'Search Recipes',
  'not_found' => 'No Recipes Found',
  'not_found_in_trash' => 'No Recipes Found in Trash',
  'parent' => 'Parent Recipe',
)
) ); }

add_action('init', 'cptui_register_my_taxes_r_cat');
function cptui_register_my_taxes_r_cat() {
register_taxonomy( 'r_cat',array (
  0 => 'recipes',
),
array( 'hierarchical' => true,
'label' => 'Recipe Categories',
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'healthy-recipes' ),
    'show_admin_column' => false,
    'labels' => array (
  'search_items' => 'Recipe Category',
  'popular_items' => '',
  'all_items' => '',
  'parent_item' => '',
  'parent_item_colon' => '',
  'edit_item' => '',
  'update_item' => '',
  'add_new_item' => '',
  'new_item_name' => '',
  'separate_items_with_commas' => '',
  'add_or_remove_items' => '',
  'choose_from_most_used' => '',
)
) ); 
}

When I just set the taxonomy to: 'rewrite' => array( 'slug' => 'healthy-recipes' ), The result is a 404 page.

When I just set it to: 'rewrite' => true, The result is a URL like this: http://website.com/r_cat/gluten-free-recipes/

What I really need is a URL like: http://website.com/gluten-free-recipes/

What do I need to change, or maybe add...to achieve this structure?

What else do you need to know?

Thanks in advance!

Your Answer

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

Browse other questions tagged or ask your own question.