WP_Query::is_post_type_archive( mixed $post_types = '' )

Is the query for an existing post type archive page?


Description Description


Parameters Parameters

$post_types

(mixed) (Optional) Post type or array of posts types to check against.

Default value: ''


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: wp-includes/class-wp-query.php

3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
public function is_post_type_archive( $post_types = '' ) {
    if ( empty( $post_types ) || ! $this->is_post_type_archive ) {
        return (bool) $this->is_post_type_archive;
    }
 
    $post_type = $this->get( 'post_type' );
    if ( is_array( $post_type ) ) {
        $post_type = reset( $post_type );
    }
    $post_type_object = get_post_type_object( $post_type );
 
    return in_array( $post_type_object->name, (array) $post_types );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.