WP_Query::is_attachment() – Is the query for an existing attachment page?
You appear to be a bot. Output may be restricted
Description
Is the query for an existing attachment page?
Usage
$bool = WP_Query::is_attachment( $attachment );
Parameters
- $attachment
- ( int|string|int[]|string[] ) optional – Optional. Attachment ID, title, slug, or array of such to check against. Default empty.
Returns
bool Whether the query is for an existing attachment page.
Source
File name: wordpress/wp-includes/class-wp-query.php
Lines:
1 to 25 of 25
public function is_attachment( $attachment = '' ) { if ( ! $this->WP_Query::is_attachment ) { return false; } if ( empty( $attachment ) ) { return true; } $attachment = array_map( 'strval', (array) $attachment ); $post_obj = $this->WP_Query::get_queried_object(); if ( ! $post_obj ) { return false; } if ( in_array( (string) $post_obj->ID, $attachment, true ) ) { return true; } elseif ( in_array( $post_obj->post_title, $attachment, true ) ) { return true; } elseif ( in_array( $post_obj->post_name, $attachment, true ) ) { return true; } return false; }