<p>I don't think the accepted answer actually works, <code>order: 'score'</code> only works if you are doing a search. </p>

<p>I've made a plugin called <a href="https://github.com/aelvan/Similar-Craft" rel="nofollow">Similar</a> that orders by the number of relations to other element types, like tags.</p>

CC BY-SA 3.0
2016-03-30T15:25:38.087Z
2016-03-30T15:25:38.087Z
André Elvan
<p>This should work:</p>

<pre><code>{% set tags = entry.q_tags %}
{% set entries = craft.entries.relatedTo(tags).order('score').find() %}
</code></pre>

CC BY-SA 3.0
2015-02-23T17:45:34.697Z
How would you stop the current entry from displaying as a related entry?
Steven Grant
CC BY-SA 3.0
2015-02-24T08:16:42.087Z
Try adding .id('not ' ~ entry.id) to your criteria.
Paul
CC BY-SA 3.0
2016-04-06T19:30:25.333Z
Ordering by `'score'` only works in the context of doing a `search: 'something'`.
Brad Bell
CC BY-SA 3.0
2014-07-18T10:29:24.393Z
Do you not want to pass an array in this situation? I.e. omit the `.first` to make `{% set tags = entry.q_tags %}` and then just pass that to the relatedTo param.
Josh Angell
CC BY-SA 3.0
2014-07-18T11:05:22.240Z
Didn't notice the 'first' :)
Paul
CC BY-SA 3.0
2014-07-18T10:24:50.940Z
2014-07-18T11:04:57.930Z
2014-07-18T11:04:57.930Z
Paul
<p>Here's how you would exclude the current entry from showing within that output if so desired</p>

<pre><code>{% set entries = craft.entries({
  relatedTo:      tags,
  order:          'score',
  limit:           4,
  id:             'not ' ~ entry.id
}) %}
</code></pre>

CC BY-SA 3.0
2016-04-06T19:30:13.113Z
Ordering by `'score'` only works in the context of doing a `search: 'something'`.
Brad Bell
CC BY-SA 3.0
2015-02-23T17:56:02.943Z
2015-02-23T17:56:02.943Z
Steven Grant
<p>On an entry page I search for related entries based on the tags assigned to the respective entry. The following example works:</p>

<pre><code>{% set tags = entry.q_tags.first %}

{% for tag in entry.q_tags.offset(1) %}
    {% set tags = tags ~ ' OR ' ~ tag  %}
{% endfor %}

{% set entries = craft.entries.search(tags).order('score') %}
</code></pre>

<p>I just wonder whether there is a smarter solution?</p>

<tags><search>
Search for related entries based on tags
# Search for related entries based on tags

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

On an entry page I search for related entries based on the tags assigned to the respective entry. The following example works:
{% set tags = entry.q_tags.first %}

{% for tag in entry.q_tags.offset(1) %}
    {% set tags = tags ~ ' OR ' ~ tag  %}
{% endfor %}

{% set entries = craft.entries.search(tags).order('score') %}

I just wonder whether there is a smarter solution?

**Tags:** tags, search


---

## 3 answers

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

I don't think the accepted answer actually works, `order: 'score'` only works if you are doing a search.

I've made a plugin called [Similar](https://github.com/aelvan/Similar-Craft) that orders by the number of relations to other element types, like tags.


---

### Answer by username_2 on 2014-07-18. Score: 5

This should work:
{% set tags = entry.q_tags %}
{% set entries = craft.entries.relatedTo(tags).order('score').find() %}

> **Comments:**
> **username_5**: Do you not want to pass an array in this situation? I.e. omit the `.first` to make `{% set tags = entry.q_tags %}` and then just pass that to the relatedTo param.  
> **username_2**: Didn't notice the 'first' :)  
> **username_3**: How would you stop the current entry from displaying as a related entry?  
> **username_2**: Try adding .id('not ' ~ entry.id) to your criteria.  
> **username_4**: Ordering by `'score'` only works in the context of doing a `search: 'something'`.  

---

### Answer by username_3 on 2015-02-23. Score: 4

Here's how you would exclude the current entry from showing within that output if so desired
{% set entries = craft.entries({
  relatedTo:      tags,
  order:          'score',
  limit:           4,
  id:             'not ' ~ entry.id
}) %}

> **Comments:**
> **username_4**: Ordering by `'score'` only works in the context of doing a `search: 'something'`.  

---

