<p>What could work for you is to get the events for each field separatly:</p>

<pre><code>{% set firstEvents = craft.entries.section('events').relatedTo({
    element: user,
    field: 'firstEntriesField'
}) %}

{% set secondEvents = craft.entries.section('events').relatedTo({
    element: user,
    field: 'secondEntriesField'
}) %}
</code></pre>

<p>If you need them combined in one loop, I can't think of another way other than to query x + 1 times:</p>

<pre><code>{% set allEvents = craft.entries.section('events').relatedTo({
    element: user,
}) %}

{% set firstEventsIds = craft.entries.section('events').relatedTo({
    element: user,
    field: 'firstEntriesField'
}).ids() %}

{% set secondEventsIds = craft.entries.section('events').relatedTo({
    element: user,
    field: 'secondEntriesField'
}).ids() %}

{% for event in allEvents %}
    {% if event.id in firstEventsIds %}
        {# Event related through firstEntriesField #}
    {% elseif event.id in secondEventsIds %}
        {# Event related through secondEntriesField #}
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-08-14T06:10:48.963Z
2015-08-15T20:05:25.310Z
2015-08-15T20:05:25.310Z
carlcs
<p>If I’m finding all the entries that are related to a user, how could I get the field handle that the found user is referenced from?</p>

<pre><code>{% set events = craft.entries.section('events').relatedTo(user) %}
{% for event in events %}

  {# What goes here? Hypothetical code based on non-existent method would be: #}

  {% set field = craft.fields.relatedTo(user) %}
  {{ field.title }}

{# Obviously this isn't possible. Any way to accomplish something like this? #}

{% endfor %}
</code></pre>

<p>There are multiple users fields in the found entries, and there will be different logic depending on which field the user is found.</p>

CC BY-SA 3.0
2015-08-14T01:02:15.127Z
Possible duplicate http://craftcms.stackexchange.com/a/720/101
Mark Busnelli Jr
CC BY-SA 3.0
2015-08-14T01:05:58.023Z
@MarkBusnelliJr Not quite, the main question here isn't how to find the related entries, but how to find & display the field handle that the relation is referenced.
Chase Giunta
<relations><field>
Find entries related to user and display field name
# Find entries related to user and display field name

(Asked by: username_0 on 2015-08-13)

If I’m finding all the entries that are related to a user, how could I get the field handle that the found user is referenced from?
{% set events = craft.entries.section('events').relatedTo(user) %}
{% for event in events %}

  {# What goes here? Hypothetical code based on non-existent method would be: #}

  {% set field = craft.fields.relatedTo(user) %}
  {{ field.title }}

{# Obviously this isn't possible. Any way to accomplish something like this? #}

{% endfor %}

There are multiple users fields in the found entries, and there will be different logic depending on which field the user is found.

**Tags:** relations, field
> **Comments:**
> **username_1**: Possible duplicate http://craftcms.stackexchange.com/a/720/101  
> **username_0**: @MarkBusnelliJr Not quite, the main question here isn't how to find the related entries, but how to find & display the field handle that the relation is referenced.  

---

## 1 answers

### Answer by username_2 on 2015-08-14. Score: 4 | Accepted answer

What could work for you is to get the events for each field separatly:
{% set firstEvents = craft.entries.section('events').relatedTo({
    element: user,
    field: 'firstEntriesField'
}) %}

{% set secondEvents = craft.entries.section('events').relatedTo({
    element: user,
    field: 'secondEntriesField'
}) %}

If you need them combined in one loop, I can't think of another way other than to query x + 1 times:
{% set allEvents = craft.entries.section('events').relatedTo({
    element: user,
}) %}

{% set firstEventsIds = craft.entries.section('events').relatedTo({
    element: user,
    field: 'firstEntriesField'
}).ids() %}

{% set secondEventsIds = craft.entries.section('events').relatedTo({
    element: user,
    field: 'secondEntriesField'
}).ids() %}

{% for event in allEvents %}
    {% if event.id in firstEventsIds %}
        {# Event related through firstEntriesField #}
    {% elseif event.id in secondEventsIds %}
        {# Event related through secondEntriesField #}
    {% endif %}
{% endfor %}


---

