.relatedTo() not returning tags with spaces I think I'm seeing a bug while using advanced search with relatedTo(). If I use a simple search, like this:

{% set param = {
   order: 'RAND()',
   limit: null,
   search: "#{request.tags}"
} %}


It finds a tag like low confidence without any issue. However, using the code I have below throws no errors, but returns no results:

{% set request = craft.request.getQuery() %}

{% set param = {
  order: 'RAND()',
  limit: null,
} %}

{% set param = craft.config.devMode or craft.config.staging
             ? param|merge({ group: 'testing' })
             : param|merge({ group: 'verified' }) %}

{% set relatedToParam = ['and'] %}

{% if request.tags %}
  {% set tagId = craft.tags.group('specialism').slug(request.tags).ids() %}
  {% set relatedToParam = relatedToParam|merge([{
    targetElement: tagId,
    field: 'tagsSpecialism',
  }]) %}
{% endif %}

{% if relatedToParam|length &gt; 1 %}
    {% set param = param|merge({ relatedTo: relatedToParam }) %}
{% endif %}

{% set users = craft.users(param) %}


I'm fairly confident it's not an issue with my code, as every other search combination is working.

Update

This is expected behaviour and requires proper hyphenated slug-path to work properly with .slug() in my code sample. See answer below!
In your working example, you’re mapping request.tags to the search param, but in the non-working example, you’re mapping it to the slug param.

Those two params are handled in very different ways. search will do some normalization routines on the value, and perform a very loose search for those keywords (see https://craftcms.com/docs/searching for more details). But the slug param will actually look for an exact match.

So if request.tags is set to "low confidence" and you pass that value into a slug param, I have complete confidence that it will return zero results, since "low confidence" isn’t actually a valid slug (see what I did there?).

You would have slightly better luck passing request.tags through the kebab filter, which will make the value look a little more like a valid slug. But the search param is probably a better bet unless you know for sure that request.tags is actually going to be a slug.