function attachment_search( $query ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'post', 'attachment' ) ); $query->set( 'post_status', array( 'publish', 'inherit' ) ); } return $query; } add_filter( 'pre_get_posts', 'attachment_search' );
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter