add_filter( 'relevanssi_indexing_restriction', 'rlv_exclude_unattached' ); function rlv_exclude_unattached( $restriction ) { global $wpdb; $restriction['mysql'] .= " AND post.ID NOT IN (SELECT ID FROM $wpdb-post WHERE post_type = 'attachment' AND post_parent = 0) "; $restriction['reason'] .= ' Not attached to a post.'; return $restriction; }