1

I visit archive page link

http://src.wordpress-develop.dev/2016/

or

http://src.wordpress-develop.dev/category/Markup/,

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?

  • Run it on a custom post type archive page – Pieter Goosen Jul 5 '16 at 10:02
2

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.

1

http://src.wordpress-develop.dev/category/Markup/ 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: http://src.wordpress-develop.dev/(post-type)

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',
    array(
      '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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.