How to get Category URL from field in Matrix This is my Matrix set up:



I'm stumped to how to get the Categories URL.

{% for block in entry.galleriesItem %}
    {% switch block.type %}

        {% case "galleriesItem" %}
            &lt;a href="{{ block.linkTo.first().url() }}"&gt;
                &lt;div class="grid-item panel {% if loop.index is divisible by(3) %}last{% endif %}"&gt;
                    {% for asset in block.image %}
                        &lt;img src="{{ asset.getUrl }}"  alt="{{ asset.title }}"/&gt;
                    {% endfor %}

                    &lt;div class="bg-white panel__title"&gt;
                        &lt;span class="cta-link cta-link--black"&gt;{{ block.galleryType }}&lt;/span&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/a&gt;
    {% endswitch %}
{% endfor %}


I previously used:

{{ block.linkTo.first().url() }}


when the field type was an entry.
{{ block.linkTo.first().url() }} looks basically right, but a couple of things could be going wrong here:


Does the Galleries category have a url assigned? (make sure the "Categories in this group have their own URLs" box is checked)
Is there a category? You should always check, even if it is a required field. You can do {% if block.linkTo.first() %}...{% endif %} or {{ block.linkTo.first().url() ?? '' }} and use the A null coalescing operator.