Answers.Body: <p>After chatting on Discord a bit more, here's a solution in case it helps somebody:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{# Base query #}
  {% set baseQuery = craft
      .entries
      .section('stories')
      .orderBy('RAND()')
      .with(['storyKeywords']) %}
  
  {# Fetch one story at random #}
  {% set baseStory = baseQuery.one() %}
  
  Base random story: {{ baseStory.title }}&lt;br&gt;
  
  {# Fetch a second story related to `baseStory` at random #}
  {% set relatedStory = clone(baseQuery)
      .relatedTo({
          targetElement: baseStory.storyKeywords,
          field: 'storyKeywords'
      })
      .id('not ' ~ baseStory.id)
      .one() %}
  
  Related Story: {{ relatedStory.title }}&lt;br&gt;
  
  {% set baseKeywords = baseStory.storyKeywords %}
  {% set relatedKeywords = relatedStory.storyKeywords %}
  
  &lt;hr&gt;
  All tags in common: {{ baseKeywords | filter((tag) =&gt; tag.title in relatedKeywords) | join(', ') }} &lt;br&gt;
  Number of tags in common: {{ baseKeywords | filter((tag) =&gt; tag.title in relatedKeywords) | length }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-05T13:04:43.253Z
Answers.Text: This is working like a dream! Thank you.
Answers.UserDisplayName: richardpixel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-05T13:03:08.190Z
Answers.LastActivityDate: 2020-05-05T13:08:16.647Z
Answers.LastEditDate: 2020-05-05T13:08:16.647Z
Answers.UserDisplayName: Oli
Answers.Body: <p>You could do the following:</p>
  
  <pre><code>{# Fetch tags from your current entry's tag field #}
  {% set tags = entry.tagFieldHandle.ids() %}
  
  {# Query entries related to your tags #}
  {% set entries = craft.entries.relatedTo(tags).all() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-04T14:43:56.020Z
Answers.Text: Thanks but still a little confused. What IDs would I be putting here? I don't want to specify any specific tags or entries, I just need to get back 2 random entries which share at least 2 tags (ideally).
  
  Does that make sense?
Answers.UserDisplayName: richardpixel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-04T13:32:34.260Z
Answers.LastActivityDate: 2020-05-04T13:32:34.260Z
Answers.UserDisplayName: Oli
Body: <p>I need to be able to display entries (within one section) that share keywords. I don't care what the keywords are, just want to display the entries based on 2 or more shared keywords.</p>
  
  <p>Anyone know how to go about this?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-01T13:26:55.533Z
Comments.Text: Are you adding tags (as per your title) to the entry or you want to compare two block of text for words in common?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-01T17:18:39.413Z
Comments.Text: Tags will be added to the entries and it's those that we need to use to link the entries together.
Comments.UserDisplayName: richardpixel
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-04T09:44:41.820Z
Comments.Text: Any ideas @Oli?
Comments.UserDisplayName: richardpixel
Tags: <relations><tags>
Title: Display entries which share tags (2 or more)
ThreadText: # Display entries which share tags (2 or more)
  
  (Asked by: username_0 on 2020-04-28)
  
  I need to be able to display entries (within one section) that share keywords. I don't care what the keywords are, just want to display the entries based on 2 or more shared keywords.
  
  Anyone know how to go about this?
  
  **Tags:** relations, tags
  
  > **Comments:**
  > **username_1**: Are you adding tags (as per your title) to the entry or you want to compare two block of text for words in common?  
  > **username_0**: Tags will be added to the entries and it's those that we need to use to link the entries together.  
  > **username_0**: Any ideas @username_1?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-05-05. Score: 2 | Accepted answer
  
  After chatting on Discord a bit more, here's a solution in case it helps somebody:
  
  ```twig
  {# Base query #}
  {% set baseQuery = craft
      .entries
      .section('stories')
      .orderBy('RAND()')
      .with(['storyKeywords']) %}
  
  {# Fetch one story at random #}
  {% set baseStory = baseQuery.one() %}
  
  Base random story: {{ baseStory.title }}<br>
  
  {# Fetch a second story related to `baseStory` at random #}
  {% set relatedStory = clone(baseQuery)
      .relatedTo({
          targetElement: baseStory.storyKeywords,
          field: 'storyKeywords'
      })
      .id('not ' ~ baseStory.id)
      .one() %}
  
  Related Story: {{ relatedStory.title }}<br>
  
  {% set baseKeywords = baseStory.storyKeywords %}
  {% set relatedKeywords = relatedStory.storyKeywords %}
  
  <hr>
  All tags in common: {{ baseKeywords | filter((tag) => tag.title in relatedKeywords) | join(', ') }} <br>
  Number of tags in common: {{ baseKeywords | filter((tag) => tag.title in relatedKeywords) | length }}
  
  ```
  
  > **Comments:**
  > **username_0**: This is working like a dream! Thank you.  
  
  ---
  
  ### Answer by username_1 on 2020-05-04. Score: 1
  
  You could do the following:
  
  ```
  {# Fetch tags from your current entry's tag field #}
  {% set tags = entry.tagFieldHandle.ids() %}
  
  {# Query entries related to your tags #}
  {% set entries = craft.entries.relatedTo(tags).all() %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks but still a little confused. What IDs would I be putting here? I don't want to specify any specific tags or entries, I just need to get back 2 random entries which share at least 2 tags (ideally).  Does that make sense?  
  
  ---
  
  