relevanssi_get_attachment_posts_query_final

apply_filters( 'relevanssi_get_attachment_posts_query_final', string $query, int $limit, string $meta_join, string $meta_where )

Filters the final SQL query that fetches posts with attachments.

Parameters

$query
(string) The SQL query that fetches attachment posts. Defaults to "SELECT DISTINCT(ID) FROM $wpdb->posts $meta_join WHERE post_type = 'attachment' AND post_status = 'inherit' AND post_mime_type LIKE 'application/%' $meta_where LIMIT 1", where 1 is the value of $limit.

$limit
(int) The number of posts to fetch. The default is 1.

$meta_join
(string) The SQL meta query JOIN clause.

$meta_query
(string) The SQL meta query WHERE clause.

More information

See the documentation for relevanssi_get_attachment_posts_query. This filter hook filters the same query slightly later, so you can adjust it without worrying about the prepared statements. That makes some use cases easier.

With relevanssi_get_attachment_posts_query, you have to do tricks like this:

add_filter( 'relevanssi_get_attachment_posts_query', function( $query ) {
  return str_replace(
    "post_type = 'attachment' AND post_status = 'inherit' AND post_mime_type LIKE %s", 
    "post_type = 'documentat' AND post_status = 'publish' AND (post_mime_type LIKE %s OR post_mime_type = '')",
    $query
  );
} );

With this filter hook, you can just do this:

add_filter( 'relevanssi_get_attachment_posts_query_final', function( $query ) {
  return str_replace(
    "post_type = 'attachment' AND post_status = 'inherit' AND post_mime_type LIKE 'application/%'", 
    "post_type = 'document' AND post_status = 'publish'",
    $query
  );
} );