Archive pages show a list of posts for a specific custom type. They help visitors find all items of that type in one place.
Archive pages for custom types in Wordpress
register_post_type('custom_type', [ 'label' => 'Custom Type', 'public' => true, 'has_archive' => true, 'rewrite' => ['slug' => 'custom-type'], // other args ]);
Set has_archive to true to enable archive pages.
The rewrite slug controls the URL for the archive page.
/books/.register_post_type('book', [ 'label' => 'Books', 'public' => true, 'has_archive' => true, 'rewrite' => ['slug' => 'books'], ]);
/films/ instead of /movie/.register_post_type('movie', [ 'label' => 'Movies', 'public' => true, 'has_archive' => 'films', 'rewrite' => ['slug' => 'films'], ]);
register_post_type('event', [ 'label' => 'Events', 'public' => true, 'has_archive' => false, ]);
This code registers a 'Books' custom post type with an archive page at /books/. The archive-book.php template lists all book posts with links.
<?php // Register custom post type with archive function my_custom_post_type() { register_post_type('book', [ 'label' => 'Books', 'public' => true, 'has_archive' => true, 'rewrite' => ['slug' => 'books'], 'supports' => ['title', 'editor'], ]); } add_action('init', 'my_custom_post_type'); // Template file: archive-book.php // Place this in your theme folder to customize archive page ?> <?php get_header(); ?> <h1>Books Archive</h1> <?php if (have_posts()) : ?> <ul> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php else : ?> <p>No books found.</p> <?php endif; ?> <?php get_footer(); ?>
Flush rewrite rules after registering a new post type by visiting Settings > Permalinks or calling flush_rewrite_rules() once.
Archive template files follow the pattern archive-{post_type}.php to customize each archive page.
If no custom archive template exists, WordPress falls back to archive.php or index.php.
Set has_archive to true when registering a custom post type to enable archive pages.
Use archive-{post_type}.php template files to customize archive page layout.
Archive pages list all posts of that custom type for easy browsing.