<p>The Similar plugin allows access to its <code>find()</code> method from PHP and your Element API configuration file.</p>

<pre><code>$similarEntriesByTags = craft()-&gt;similar-&gt;find([
    element =&gt; $entry,
    context =&gt; $entry-&gt;tags,
    criteria =&gt; $limitCriteria,
]);
</code></pre>

<p>This is the equivalent to the Twig example code in the readme.</p>

<pre><code>{% set similarEntriesByTags = craft.similar.find({ element: entry, context: entry.tags }) %}
</code></pre>

<p>If you’re inexperienced in quering for entries or using element criteria in PHP in general have a look a the <a href="https://craftcms.com/docs/plugins/working-with-elements" rel="nofollow">Working with Elements</a> article in the Craft documentation.</p>

CC BY-SA 3.0
2016-09-30T16:06:03.723Z
2016-09-30T18:09:35.243Z
2016-09-30T18:09:35.243Z
carlcs
<p>How can I pull out other entries related by tag using the Element API?</p>

<p>In this particular case I'm using the <a href="https://github.com/aelvan/Similar-Craft" rel="nofollow">Similar</a> plugin to pull out related entries by tag in the templates. I'm not sure if this would help to provide an easier way or not...?</p>

<tags><plugin-elementapi>
Element API: List entries related by tag
# Element API: List entries related by tag

(Asked by: username_0 on 2016-09-30)

How can I pull out other entries related by tag using the Element API?

In this particular case I'm using the [Similar](https://github.com/aelvan/Similar-Craft) plugin to pull out related entries by tag in the templates. I'm not sure if this would help to provide an easier way or not...?

**Tags:** tags, plugin-elementapi

---

## 1 answers

### Answer by username_1 on 2016-09-30. Score: 1 | Accepted answer

The Similar plugin allows access to its find() method from PHP and your Element API configuration file.
$similarEntriesByTags = craft()->similar->find([
    element => $entry,
    context => $entry->tags,
    criteria => $limitCriteria,
]);

This is the equivalent to the Twig example code in the readme.
{% set similarEntriesByTags = craft.similar.find({ element: entry, context: entry.tags }) %}

If you’re inexperienced in quering for entries or using element criteria in PHP in general have a look a the Working with Elements article in the Craft documentation.


---

