Add attachments to search results WordPress

PHOTO EMBED

Wed Aug 10 2022 09:53:31 GMT+0000 (Coordinated Universal Time)

Saved by @lancerunsite #wordpress #search #attachments

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' );
content_copyCOPY

https://casabona.org/2014/12/add-attachments-wordpress-search-results/