Answers.Body: <p>Your issue is probably that your syntax for the <a href="https://craftcms.com/docs/3.x/entries.html#section" rel="nofollow noreferrer"><code>section()</code></a> query parameter is a bit off.</p>
  <p>Currently, you're passing the section handles <code>'MenuB'</code> and <code>'MenuA'</code> as separate arguments to the <code>section()</code> query parameter – i.e. <code>section('MenuB', 'MenuA')</code>. However, the <code>section()</code> parameter actually only takes a single argument, which is why the query ignores the second <code>'MenuA'</code> handle.</p>
  <p>When querying multiple sections you should either pass the section handles as an array:</p>
  <p><code>section(['MenuB', 'MenuA'])</code></p>
  <p>...or as a comma-separated string:</p>
  <p><code>section('MenuB,MenuA')</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-17T23:29:50.483Z
Answers.Text: Thanks Mats. Oddly enough that didn't change the outcome. However i did get the expected outcome when i specified the targetElement query to {% set entryPage = craft.entries.section('Pages').slug(firstSlug).one() %}
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-17T22:23:51.187Z
Answers.LastActivityDate: 2022-02-17T23:37:09.117Z
Answers.LastEditDate: 2022-02-17T23:37:09.117Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have an entries page structure section
  Pages</p>
  <p>And two structure sections / menus
  Menu A
  Menu B</p>
  <p>Menu A and Menu B have an entry field link called 'entryLink' that is a relation to an entry in the page section</p>
  <p>My url route looks like
  page-1/page-2/page-3</p>
  <p>I want to find the url first segment and locate it in the Menu A or Menu B entryLink field (so I can then play with children entries and same level items)</p>
  <p>So I get the first segment, locate the page and create a query to find the relation.</p>
  <p>First segment</p>
  <pre><code>{% set entryPage = craft.entries().slug(firstSlug).one() %}
  </code></pre>
  <p>Then query relation to get route</p>
  <pre><code>{% set menuItem = craft.entries.section('MenuB', 'MenuA')
              .relatedTo({
                  targetElement: entryPage,
                  field: 'entryLink'
              }).one() %}
  </code></pre>
  <p>check menu id for page accessed</p>
  <pre><code>{{ menuItem.id }}
  </code></pre>
  <p>This seems to work for a page that has a relation in Menu B.
  However for Menu A menuItem.id returns zero. I have checked that the entries exist and are related in Menu A
  Is there something wrong with my query?</p>
  <p>==== SOLVED ====</p>
  <p>Answer was changing</p>
  <pre><code>{% set entryPage = craft.entries().slug(firstSlug).one() %}
  
  </code></pre>
  <p>to</p>
  <pre><code>{% set entryPage = craft.entries.section('Pages').slug(firstSlug).one() %}
  </code></pre>
  <p>Not sure why this worked</p>
  
Tags: <relatedto><elementquery><menu>
Title: Why is my relational query returning zero?
ThreadText: # Why is my relational query returning zero?
  
  (Asked by: username_0 on 2022-02-17)
  
  I have an entries page structure section
  Pages
  
  And two structure sections / menus
  Menu A
  Menu B
  
  Menu A and Menu B have an entry field link called 'entryLink' that is a relation to an entry in the page section
  
  My url route looks like
  page-1/page-2/page-3
  
  I want to find the url first segment and locate it in the Menu A or Menu B entryLink field (so I can then play with children entries and same level items)
  
  So I get the first segment, locate the page and create a query to find the relation.
  
  First segment
  
  ```
  {% set entryPage = craft.entries().slug(firstSlug).one() %}
  
  ```
  
  Then query relation to get route
  
  ```
  {% set menuItem = craft.entries.section('MenuB', 'MenuA')
              .relatedTo({
                  targetElement: entryPage,
                  field: 'entryLink'
              }).one() %}
  
  ```
  
  check menu id for page accessed
  
  ```
  {{ menuItem.id }}
  
  ```
  
  This seems to work for a page that has a relation in Menu B.
  However for Menu A menuItem.id returns zero. I have checked that the entries exist and are related in Menu A
  Is there something wrong with my query?
  
  ==== SOLVED ====
  
  Answer was changing
  
  ```
  {% set entryPage = craft.entries().slug(firstSlug).one() %}
  
  ```
  
  to
  
  ```
  {% set entryPage = craft.entries.section('Pages').slug(firstSlug).one() %}
  
  ```
  
  Not sure why this worked
  
  **Tags:** relatedto, elementquery, menu
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-02-17. Score: 2
  
  Your issue is probably that your syntax for the [`section()`](https://craftcms.com/docs/3.x/entries.html#section) query parameter is a bit off.
  
  Currently, you're passing the section handles `'MenuB'` and `'MenuA'` as separate arguments to the `section()` query parameter – i.e. `section('MenuB', 'MenuA')`. However, the `section()` parameter actually only takes a single argument, which is why the query ignores the second `'MenuA'` handle.
  
  When querying multiple sections you should either pass the section handles as an array:
  
  `section(['MenuB', 'MenuA'])`
  
  ...or as a comma-separated string:
  
  `section('MenuB,MenuA')`
  
  > **Comments:**
  > **username_0**: Thanks username_1. Oddly enough that didn't change the outcome. However i did get the expected outcome when i specified the targetElement query to {% set entryPage = craft.entries.section('Pages').slug(firstSlug).one() %}  
  
  ---
  
  