Aside: Custom Post Types Archives in WordPress

Did you know that register_post_type has got a has_archive argument which can be set to a string? In which case it will use that string as a slug for the archives and generate the proper rewrite rules for you. Don’t forget to visit your permalinks settings page though to flush rules when making changes.

5 thoughts on “Aside: Custom Post Types Archives in WordPress

  1. I prefer using a custom theme and assigning it to a page for the index of my custom post type. Doing so enables a physical page rather than relying on a theme file (archive-$posttype.php). Its better for menu building as well.

    • You mean a page template? I agree it could be tempting but how do you then manage things like pagination, etc? Do you filter on pre_get_posts to replace the query before it’s fired? Thanks for your comment!

    • Hi Unsal, not sure what you mean by “properly” but you can always drop the menu item as a custom link to your archive. It will stop working if links change in the future though, so you’ll have to keep an eye on that.

    • I agree with Konstantin: the benefits of auto-pagination far outweigh those of having a page template emulate the archive function.

      As for the menus, custom links are the way to go, perhaps combining them with this technique to enable proper styling of the menu item when visiting child nodes.

Comments are closed.