<p>If you want to limit your relationships to a particular field, use this syntax:</p>

<pre><code>$criteria-&gt;relatedTo = array(
    'targetElement' =&gt; $element,
    'field' =&gt; $field
);
</code></pre>

<p>I believe 'field' will take:</p>

<p>1) A single or array of $field instances</p>

<p>2) A single or array of field IDs or field handles.</p>

CC BY-SA 3.0
2014-07-11T00:12:21.657Z
That did! Appreciate it Brad.
Peter Tell
CC BY-SA 3.0
2014-07-10T23:39:16.923Z
2014-07-10T23:39:16.923Z
Brad Bell
<p>So,</p>

<p>I want to grab all entries that are related to an entry but with the following criteria:</p>

<ol>
<li>Only from my section ($section)</li>
<li>Only the ones that have been added to a certain field ($fieldId)</li>
</ol>

<p>I currently have this:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = $section;
$criteria-&gt;limit   = null;
$criteria-&gt;relatedTo = array(
    'targetElement' =&gt; $element,
);
$elements = craft()-&gt;elements-&gt;findElements($criteria);
return $elements;
</code></pre>

<p>But if I add two relationship fields to an entry, this will return ALL the associated entries from either field. I want to limit it to just the entries attached to the one field.</p>

<p>Is this possible? Does the question make sense? :-)</p>

<plugin-development>
Is it possible to grab related entries that have been attached to a certain field?
# Is it possible to grab related entries that have been attached to a certain field?

(Asked by: username_0 on 2014-07-10)

So,
I want to grab all entries that are related to an entry but with the following criteria:

Only from my section ($section)
Only the ones that have been added to a certain field ($fieldId)

I currently have this:
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = $section;
$criteria->limit   = null;
$criteria->relatedTo = array(
    'targetElement' => $element,
);
$elements = craft()->elements->findElements($criteria);
return $elements;

But if I add two relationship fields to an entry, this will return ALL the associated entries from either field. I want to limit it to just the entries attached to the one field.
Is this possible? Does the question make sense? :-)

**Tags:** plugin-development

---

## 1 answers

### Answer by username_1 on 2014-07-10. Score: 4 | Accepted answer

If you want to limit your relationships to a particular field, use this syntax:
$criteria->relatedTo = array(
    'targetElement' => $element,
    'field' => $field
);

I believe 'field' will take:
1) A single or array of $field instances
2) A single or array of field IDs or field handles.

> **Comments:**
> **username_0**: That did! Appreciate it Brad.  

---

