I've just moved a site I'm developing to WP3.1 so that I can take advantage of and start testing some of the new features. I'm especially liking the has_archive parameter in registering custom post types. I had a post type called 'recipes', and added this line to the args on registering it:

'has_archive' => 'recipe-listings',

From what I understand, that should generate the rewrite rules necessary to make /recipe-listings/ be equivalent to /?post_type=recipe. However, I can't seem to get it working.

The generic form http://amritafood.com/?post_type=recipe works fine, but http://amritafood.com/recipe-listings/ just goes to 404. What else do I need to do to get custom post type archives working properly? Has anyone else worked it out yet?

  • 1
    Just to be clear: did you flush your rewrite rules already? Do links to individual posts work? – Jan Fabry Dec 3 '10 at 20:56
  • Yeah, I ran the flush_rewrite_rules once, and the links to individual posts work fine. The url ?post_type=recipe is pulling from my archive-recipe.php template, so the archive functionality seems to be working. Guess I'm just having a problem with generating the rewrite rules. – goldenapples Dec 3 '10 at 21:01
  • Doh... never mind. I was flushing rules at the wrong point. Flushing rules after the post types were registered did the trick. Thanks. – goldenapples Dec 3 '10 at 21:05

I asked the question too soon. And thanks to @Jan Fabry for pointing me in the right direction.

In case anyone else has this problem, here's the answer.

Any time the rewrite rules are changed (adding a new post type, changing the slug or the has_archive slug, etc.) you have to call flush_rewrite_rules once. It has to be called after the post types are registered. I put it at the very end of my function which registered the post types on 'init', visited the site once, then deleted it out. Now the site works fine.

|improve this answer|||||
  • 2
    You don't even need to do that, just visit the permalink settings page and hit save, it's harder to get this process wrong.. ;) – t31os Dec 4 '10 at 10:02
  • 7
    @t31os: Even quicker: don't hit save, the rules are flushed just by loading the permalink settings page. – Jan Fabry Dec 4 '10 at 13:29
  • I thought that were the case, but figured an extra click wouldn't hurt... :) – t31os Dec 4 '10 at 17:10

Your Answer

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

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