I created a new custom post type called event, which works fine.

I also created a custom 404 page template, which is shown if a event/page/post is not found.

But now the hard part, i want to create a custom 404 page for event post type. So this 404 page is only shown if a event is not found. But the default 404 page should still work with posts or pages.



Two options:

  1. Use conditional code inside of 404.php, to output different content/markup for the post-type
  2. Intercept the template at template_redirect, and include a separate template file for a 404 for the post-type.

Personally, I'd go with option 1, as it is easier and more intuitive.

  • On the other hand, using a 404-posttype.php like single-posttype.php might be easier to understand for the next developer. – fuxia Dec 12 '12 at 21:47
  • But the Template Hierarchy doesn't account for anything other than 404.php, so support would have to be added by filtering template_include; thus I'm not sure how intuitive it would be for a subsequent developer? – Chip Bennett Dec 12 '12 at 22:53
  • You could call that file from 404.php too (and return; then), so implementation details are rather open. I had the file list in mind. – fuxia Dec 12 '12 at 23:02

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.