WordPress is_post_type_archive() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_post_type_archive() returns true on the archive page of a post type, such as /books/ for a book post type.

The post type must have has_archive set to true when you register it. Call the tag with no argument to match any post type archive, or pass a name to match one.

Syntax

Use it as the test of an if statement.

WordPress
if ( is_post_type_archive() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_post_type_archive()True on any post type archive.
is_post_type_archive( 'book' )True on the archive of the book post type.
is_post_type_archive( array( 'book', 'movie' ) )True on either archive.

The theme file is archive-book.php for a post type named book.

Full declaration
WordPress
is_post_type_archive( string|string[] $post_types = '' ): bool

Parameters

ParameterDescription
$post_typesOptional. A post type name or an array of names. Default is empty, which means any post type archive.

Return Value

Return ValueDescription
booltrue if the main query is for a post type archive, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Archive heading

Print the post type title on its archive.

WordPress
<?php if ( is_post_type_archive() ) {
  post_type_archive_title( '<h1>', '</h1>' );
} ?>

How It Works

  1. is_post_type_archive() is true on custom post type archives.
  2. post_type_archive_title() prints the label of the post type.
  3. Other pages skip the heading.

Example 2 — One post type

Show a note on the Books archive only.

WordPress
<?php if ( is_post_type_archive( 'book' ) ) {
  echo '<p>Browse every book we reviewed.</p>';
} ?>

How It Works

  1. 'book' is the post type name.
  2. Only that archive returns true.
  3. Other archives skip the note.

Example 3 — Wide layout for an archive

Use a different layout class.

WordPress
<?php $class = is_post_type_archive( 'book' ) ? 'grid' : 'list'; ?>
<main class="<?php echo esc_attr( $class ); ?>">

How It Works

  1. The short ? : form picks a class name.
  2. esc_attr() makes the value safe.
  3. Your CSS can style .grid as a card layout.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
Make sure has_archive is true in register_post_type() and that you flushed the permalinks.
No. A single custom post is checked with is_singular( 'book' ) or is_single().
No. The posts index uses is_home().
Conditional tags need the main query. Call them in template files or on hooks such as wp or template_redirect, not directly at the top of functions.php.

Next: is_preview()

Check if a post is being viewed in preview mode.

is_preview() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful