WP_Query::is_post_type_archive() – Is the query for an existing post type archive page?

You appear to be a bot. Output may be restricted

Description

Is the query for an existing post type archive page?

Usage

$bool = WP_Query::is_post_type_archive( $post_types );

Parameters

$post_types
( string|string[] ) optional – Optional. Post type or array of posts types to check against. Default empty.

Returns

bool Whether the query is for an existing post type archive page.

Source

File name: wordpress/wp-includes/class-wp-query.php
Lines:

1 to 17 of 17
  public function is_post_type_archive( $post_types = '' ) {
    if ( empty( $post_types ) || ! $this->WP_Query::is_post_type_archive ) {
      return (bool) $this->WP_Query::is_post_type_archive;
    }

    $post_type = $this->WP_Query::get( 'post_type' );
    if ( is_array( $post_type ) ) {
      $post_type = reset( $post_type );
    }
    $post_type_object = get_post_type_object( $post_type );

    if ( ! $post_type_object ) {
      return false;
    }

    return in_array( $post_type_object->name, (array) $post_types, true );
  }
 

 View on GitHub View on Trac