<p>You're close!</p>

<p>In your entry query, change <code>.relatedMarkets([allMarkets])</code> to <code>.relatedTo(allMarkets)</code> (use <a href="https://docs.craftcms.com/v3/relations.html" rel="nofollow noreferrer"><code>relatedTo</code></a> instead and you don't need array brackets).</p>

<p>Final code looks like:</p>

<pre><code>{% set allMarkets = entry.relatedMarkets.all() %}
{% set currentID = entry.id %}

{% set expertBlog = craft.entries()
    .section('blog')
    .orderBy('postDate desc')
    .expertOpinion(true)
    .relatedTo(allMarkets)
    .id(['not', currentID])
    .limit(3)
%}

</code></pre>

CC BY-SA 4.0
2020-05-26T15:46:41.060Z
2020-05-26T15:46:41.060Z
RitterKnight
<p>I did something similar with entry counts. The trick was to get the ids from the first query and then use that as the sourceElement for the relatedTo query.</p>

<pre><code>{% set userMugQuery = craft.entries().section('userMugs').relatedTo({targetElement: entry}) %}
{% set userMugAssetQuery = craft.assets()
    .volume('userAssets')
    .relatedTo({ sourceElement: userMugQuery.ids(), field: 'userAssets' })
%}
{% set userMugCount = userMugQuery.count() %}
{% set userMugAssetCount = userMugAssetQuery.count() %}
</code></pre>

CC BY-SA 4.0
2020-05-22T14:20:58.797Z
2020-05-22T14:20:58.797Z
Leevi Graham
<p>I'm wanting to show related articles based on the current article's related Markets.</p>

<p>How do I get the current markets and filter relevant posts based on those related markets? This is what I have so far but doesn't seem correct.</p>

<pre><code>{% set allMarkets = entry.relatedMarkets.all() %}
{% set currentID = entry.id %}

{# Get Related Articles Based on Markets #}
{% set expertBlog = craft.entries()
    .section('blog')
    .orderBy('postDate desc')
    .expertOpinion(true)
    .relatedMarkets([allMarkets])
    .id(['not', currentID])
    .limit(3) %}

      &lt;h3 class="f3-l f3-xl fw5 mt0-l mt0-xl b tc"&gt;Enjoyed this article? Keep reading more expert insights...&lt;/h3&gt;
      &lt;div class="flex flex-wrap cf mb4 nl3-m nr3-m nl3-l nr3-l nl3-xl nr3-xl"&gt;
          {% cache %}
          {% for entry in expertBlog %}
              {% set columns = 'w-100 w-50-m w-33-l w-33-xl' %}
              {% include "_partials/lists/blog/_cards_blog_article_authors_expert.twig" %}
          {% endfor %}
          {% endcache %}
      &lt;/div&gt;
</code></pre>

CC BY-SA 4.0
2020-05-22T15:30:33.847Z
In your entry query, change ``.relatedMarkets([allMarkets])`` to ``.relatedTo(allMarkets)`` (use relatedTo instead and you don't need brackets).
RitterKnight
CC BY-SA 4.0
2020-05-26T15:28:12.837Z
Thanks if you post as an official answer I will accept.
Dan Lee
CC BY-SA 4.0
2020-05-26T15:47:08.763Z
Dan: You bet. Done.
RitterKnight
<craft3>
Query Entries based on current Entry's related Entries
# Query Entries based on current Entry's related Entries

(Asked by: username_0 on 2020-05-22)

I'm wanting to show related articles based on the current article's related Markets.
How do I get the current markets and filter relevant posts based on those related markets? This is what I have so far but doesn't seem correct.
{% set allMarkets = entry.relatedMarkets.all() %}
{% set currentID = entry.id %}

{# Get Related Articles Based on Markets #}
{% set expertBlog = craft.entries()
    .section('blog')
    .orderBy('postDate desc')
    .expertOpinion(true)
    .relatedMarkets([allMarkets])
    .id(['not', currentID])
    .limit(3) %}

      Enjoyed this article? Keep reading more expert insights...
      
          {% cache %}
          {% for entry in expertBlog %}
              {% set columns = 'w-100 w-50-m w-33-l w-33-xl' %}
              {% include "_partials/lists/blog/_cards_blog_article_authors_expert.twig" %}
          {% endfor %}
          {% endcache %}

**Tags:** craft3

> **Comments:**
> **username_1**: In your entry query, change ``.relatedMarkets([allMarkets])`` to ``.relatedTo(allMarkets)`` (use relatedTo instead and you don't need brackets).  
> **username_0**: Thanks if you post as an official answer I will accept.  
> **username_1**: Dan: You bet. Done.  

---

## 2 answers

### Answer by username_1 on 2020-05-26. Score: 1 | Accepted answer

You're close!
In your entry query, change .relatedMarkets([allMarkets]) to .relatedTo(allMarkets) (use relatedTo instead and you don't need array brackets).
Final code looks like:
{% set allMarkets = entry.relatedMarkets.all() %}
{% set currentID = entry.id %}

{% set expertBlog = craft.entries()
    .section('blog')
    .orderBy('postDate desc')
    .expertOpinion(true)
    .relatedTo(allMarkets)
    .id(['not', currentID])
    .limit(3)
%}


---

### Answer by username_2 on 2020-05-22. Score: 0

I did something similar with entry counts. The trick was to get the ids from the first query and then use that as the sourceElement for the relatedTo query.
{% set userMugQuery = craft.entries().section('userMugs').relatedTo({targetElement: entry}) %}
{% set userMugAssetQuery = craft.assets()
    .volume('userAssets')
    .relatedTo({ sourceElement: userMugQuery.ids(), field: 'userAssets' })
%}
{% set userMugCount = userMugQuery.count() %}
{% set userMugAssetCount = userMugAssetQuery.count() %}


---

