4

I'm working with the new custom post type archives in 3.1 and I noticed that when my post type has 0 posts, the archive for the type results in a 404. Looking at the order of hooks being processed, it's redirecting to the 404 template before even processing my archive-{post_type}.php template and reaching the conditional for available posts.

Reading various articles and questions here had clued me in on flushing the permalink state after creating my types. This shouldn't be an issue, however, as the archive page works if posts for the type exist. I even went as far as setting my has_archive value to the post type slug rather than just true to no avail.

Is there a way to force the archive template to be loaded and not generate a 404 regardless of post count while keeping the query in place?

3
  • One method I'm trying is to use the template_redirect action to determine if the post_type matches the requested one and redirect to the archive-{post_type}.php template. Of course, this also means hooking anything else that may act upon the 404 (title, other content modifers, etc). I'm hoping there's a more logical way of fixing this as it seems like a bandaid more than anything.
    – BigRedPimp
    Mar 10, 2011 at 17:16
  • I have the exact same problem in 3.1. A custom post type with no posts results in a 404 error message. Help please!
    – EddyR
    Mar 23, 2011 at 7:12
  • Try the Custom Post Type Archives plugin. wordpress.org/extend/plugins/custom-post-type-archives
    – kramdraw85
    Aug 23, 2011 at 16:47

1 Answer 1

4

An FYI for those coming back to this question, this was fixed in 3.2: http://core.trac.wordpress.org/ticket/17316

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.