What are the advantages of using a custom post type archive?

When you use a custom page template you run 2 sql queries to display the page: the first is ran by WordPress to get the page, the second is ran inside the page template file using secondary queries (new WP_Query).

A direct consequence of that (besides the performance impact) is that intercept the main query and, just for example, do stuff on pre_get_posts based on the query arguments is very easy when you use archives file (the query that get posts is the main), when you use a page template modify the query you run inside the template can be very hard, and possibly only way is using another template…

After that, using a post type archive users don’t need to set anything on backend, just add CPT posts and ther are shown using archive-$posttype.php.

When you use a page template users have to:

  • create a page
  • assign the page template

If your theme going to be sold or shared in some way, people that have to use have to do those 2 tasks for every cpt, using the archive-$posttype.php method, they don’t need to do anything.

Another thing on behalf of archive files is that if other developers see your theme files, and see a archive-foo.php file, immediately undestand (without open any file) that archive-foo.php is used to display posts of ‘foo’ CPT, using page templates they need to read the code or… guess.

However, yes, using a page template can be useful for something of the things that you listed and probably other.

So there is no a general rule “one is better than the other”: if you absolutely need some deep configuration for archives, then page template are useful (being aware of what are the consequences), but for some CPTs where you don’t need that configurations, the archive files are perfectly fine.

Leave a Comment