SELECT count(*) as total FROM library l INNER JOIN library_custom_fields lcf ON l.id = lcf.library_fk WHERE l.template_id = 18002 AND lcf.name = 'letter' AND lcf.value = ?