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

In this particular case I'm using the Similar 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...?

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.