When 'is_post_type_archive()' return true?

I visit archive page link




on either page is_post_type_archive() return false.

I have added is_post_type_archive() in archive.php template file.

I have tried putting is_post_type_archive() in and out the loop,
use wp_reset_query() before the is_post_type_archive(), but all return false.

How can I make is_post_type_archive() function return true?

Solutions Collecting From Web of "When 'is_post_type_archive()' return true?"

When ‘is_post_type_archive()’ return true?

is_post_type_archive() returns true for custom post type archives and false for default posts.

Use is_archive() to check for default posts.

or another link is not a post type archive page, it is a archive page. archive page is not a post type archive page. archive page access link like above, but post type archive page access link like:

replace the (post-type) with the really post type.

There is no post type archive pages for the build in post types, only for custom post types when has_archive is set(I can’t prove that). So only when you create a custom post type like this:

add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'acme_product',
      'labels' => array(
        'name' => __( 'Products' ),
        'singular_name' => __( 'Product' )
      'public' => true,
      'has_archive' => true,

then you can access your custom post type archive page through link website-url/acme-product, the template file archive-{post_type}.php or archive.php either used. In the context, either in archive-{post_type}.php or archive.php the is_post_type_archive() function return true, otherwise always return false.

is_post_type_archive (string|array $post_types = '' )

Is the query for existing post type archive page?