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 registered a custom post type using Custom Post Type UI, and created an archive page and named it archive-recipe.php, 'recipe' is my custom post type name. But its not working, instead its using the default archive.php. I set the has-archive to true but still not working. How to fix that?

Here's the code:

register_post_type(
    'recipe', array(
'label' => 'Recipe',
    'description' => 'This is a Recipe Custom Post Type',
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'capability_type' => 'post',
    'hierarchical' => true,
    'rewrite' => array('slug' => ''),
    'query_var' => true,
    'has_archive' => true,
    'exclude_from_search' => false,
    'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),
    'labels' => array (
          'name' => 'Recipe',
          'singular_name' => 'Recipe',
          'menu_name' => 'Recipe',
          '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 Recipe',
          'not_found' => 'No Recipe Found',
          'not_found_in_trash' => 'No Recipe Found in Trash',
          'parent' => 'Parent Recipe',
    ),
    )
);
share|improve this question
    
Please post the actual custom post type registration code. Also: what happens if you set permalinks to default (i.e. no rewrites), and/or reset permalink settings? –  Chip Bennett May 15 '13 at 13:01
    
Added the code on edit, I tried the default permalink and looks like its working as expected –  markyeoj May 15 '13 at 13:11
1  
Your code appears to work fine for me. Please see: wordpress.stackexchange.com/q/98995/21376 I believe ts may be a functional duplicate of that one. –  s_ha_dum May 15 '13 at 13:44
    
Looking at the rewrite slug you set, are you trying to remove the post type prefix to work like pages? If so, this will not work, and you will have to do a lot more than twiddle some flags in register_post_type, and introduce potentially site breaking bugs ( permalink clashes between pages/categories and the new post type URLs ) –  Tom J Nowell May 15 '13 at 13:45

1 Answer 1

up vote 5 down vote accepted

Given the standard registration, you should have the following:

  • A post type with the name 'recipe'
  • A recipe post archive at example.com/recipe/
  • Recipe posts with urls that take the form example.com/recipe/helloworldrecipe/
  • A template archive-recipe.php
  • A template single-recipe.php

However, I see this in your registration code:

'rewrite' => array('slug' => ''),

This suggests what you're trying to do is remove the 'recipe' prefix from recipe URLs. The result of this is that your recipe post archive is now:

site URL + ''

Which is already taken by the homepage, so your post archive is impossible to get to.

On top of this, it doesn't actually do what you think it does. You can't change a custom post type to not have the '/recipe/' part in its URLs using the register_post_type rewrite parameters alone. You need to make other changes, which also introduce potentially site breaking bugs.

For example, if you have a page called 'pumpkin' and a recipe called 'pumpkin' how is WordPress to know which to load when visiting example.com/pumpkin ? It doesn't, so it'll go for whichever rewrite rule it finds first.

So if you have a recipe for pie, but there's no page called pie, and it looks for the page and doesn't find it, you dont get the recipe, you get a 404.

So I would strongly advise you abandon your attempt. it makes your URLs make less sense, and despite the nonsense SEO "experts" say, it's more likely to harm, not help your search engine rankings if it does anything at all ( it very likely does absolutely nothing to help you ).

So remove the rewrite parameter, and resave your permalinks

Update

After you posted this link:

http://seemynewwebsite.com/g2bm/recipecategory/appetizers/

It is now clear that you're loading a taxonomy and expecting a post type archive. A taxonomy is not a post type, as you can see here, they do not share the same fallbacks:

enter image description here

What's more it doesn't make sense that they would. For example, which post type archive template would be used in these scenarios:

  • A taxonomy that contains 2 types of post type, people and locations. Would it fall back to archive-location.php or archive-people.php?
  • A user taxonomy, referring to users, not posts

So instead, use a taxonomy template for your taxonomy, not a post type archive template. In this case taxonomy-recipecategry.php

share|improve this answer
    
Thanks, good improvement, the recipe is now displaying the posts, the previous was 404.. but I'm still confuse on this, actually I thought if I view the single category example, it will use the archive-recipe.php that I created, but instead its still using the archive.php. what's wrong with that? –  markyeoj May 15 '13 at 15:26
    
Aaaaah, archive-recipe.php is for a post archive, that is not a post archive, that's a taxonomy listing, you need a taxonomy template. –  Tom J Nowell May 15 '13 at 15:58
    
thanks, I created the taxonomy-recipe.php but still no luck, its still using the archive.php.. –  markyeoj May 15 '13 at 16:21
1  
Your taxonomy is not called recipe though, recipe is a post type not a taxonomy. taxonomy-taxonomyname.php, the type of post a taxonomy lists is utterly irrelevant here –  Tom J Nowell May 15 '13 at 16:46
1  
perfect, thanks @tom for your patience, in this thread I learned a lot so much from you. Thank You so much. –  markyeoj May 15 '13 at 16:51

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.