Answers.Body: <p>The code above was missing a space after not</p>
  
  <p><code>.id('not'~entry.id)</code> should have been <code>.id('not '~entry.id)</code></p>
  
  <p>This one is an easy one to miss and I have done it a million times.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-23T17:04:10.717Z
Answers.LastActivityDate: 2016-08-23T18:45:02.700Z
Answers.LastEditDate: 2016-08-23T18:45:02.700Z
Answers.UserDisplayName: AbbeyDesign
Body: <p>I am still having a problem looping through related posts.</p>
  
  <p>I get zero, not even the HTML. And there are no Craft template errors. There are plenty of entries that were assigned the same market, so there should be something.  AND this exact approach worked perfectly before !@$!@#!</p>
  
  <pre><code>&lt;h5&gt;Similar Projects&lt;/h5&gt;
  
  {% set relatedMarket = entry.market.first() %}
  {% set relatedEntries = craft.entries.section('posts').relatedTo({ targetElement: relatedMarket, field: 'market'}).id('not'~entry.id) %}
  
  {% for relatedEntry in relatedEntries %}
      &lt;a href="{{ relatedEntry.url }}"&gt;&lt;p&gt; Entry title goes here. {{ relatedEntry.title  }} &lt;/p&gt;&lt;/a&gt;
  {% endfor %}    
  </code></pre>
  
  <p>I double checked.  My entry section handle is <code>posts</code>. The handle for the <code>posts</code> entry type is <code>notifications</code>. The category group handle is <code>markets</code>.  The category entry field handle is <code>market</code>.  I included the entry type and category group handles just in case I am missing something. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T13:49:13.323Z
Comments.Text: Are you getting any HTML on the page or is it totally blank? Are you in `devMode`?
Comments.UserDisplayName: Aaron Berkowitz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T14:16:06.920Z
Comments.Text: I am in devMode.  The rest of the page is working.  The layout is extended.  The entry title, image, body, and category all appear.  This section, however, generates nothing.  I stripped out the reference to the 'owl carousel` and stripped my example to print just the `relatedEntry.title` and `relatedEntry.url`.  It still is generating nothing.
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T14:16:29.593Z
Comments.Text: {% set relatedMarket = entry.market.first() %}
     {% set relatedEntries = craft.entries.section('posts').relatedTo(
     { targetElement: relatedMarket, field: 'market'}).id('not'~entry.id) %}
     {% for relatedEntry in relatedEntries %}
      <a href="{{ relatedEntry.url }}"><p> {{ relatedEntry.title  }} </p></a>
     {% endfor %}
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T14:54:48.283Z
Comments.Text: You could try dumping each variable to debug using `{{ dump( relatedMarket ) }}` or simply see if anything has been found by applying the `length` filter like so: `{{ relatedEntries|length }}`. What is the `length` of `relatedEntries`?
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T15:15:26.140Z
Comments.Text: `{{ relatedEntries|length }}` printed nothing. `{{ dump( relatedMarket) }}` printed, but I can't decipher it.
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T16:32:13.613Z
Comments.Text: Try using `{% set relatedMarket = craft.categories.id( entry.market.id ).first() %}`
Comments.UserDisplayName: Luke Pearce
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T20:51:40.323Z
Comments.Text: Start by making sure you're getting the relatedMarket you think you are. If you `{{ dump(relatedMarket.id }}`, is that the correct market ID you'd expect in the control panel?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T20:58:37.087Z
Comments.Text: I added `{{ dump(relatedMarket.id) }}` every entry returns the same `string(1) "4"` - even those with a different selection from the `market` field.
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T21:03:13.187Z
Comments.Text: Sorry a bit new...  `{{ dump(relatedMarket.id)}}` is showing the same `id` for all entries, even though that is not the case.
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T21:06:02.963Z
Comments.Text: And even entries with id "4" assigned print nothing.
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T22:15:22.743Z
Comments.Text: OK, work backwards from there.  Is `{{ dump(entry.id) }}` the one you think it is? Also it sounds like you've got entry in a loop?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T23:13:33.497Z
Comments.Text: `{{ dump(entry.id) }}`  a sample result is `string(2) "42"`or `string(1) "3"`,  the second # corresponds to an entry's `id`.   I am not sure what the (2) or (1) denotes.   But, of the 11 test entries all but one is (2).
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-22T23:22:38.270Z
Comments.Text: So, to put another way...  what am I looking for?   I am confused.   `{{ dump(relatedMarket.id) }}` shows everything to be `(1)"4"`.  If I assume this is a reference to the `category group id` and 'category id' then something seems off.  The reported `category group id` is correct, but different `category id` should be appearing across the test entries.
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-23T16:44:06.383Z
Comments.Text: Shouldn't .id('not'~entry.id) have a space in it? .id('not '~entry.id)
Comments.UserDisplayName: AbbeyDesign
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-23T16:44:11.740Z
Comments.Text: I was able to address dump(relatedMarket) depicting the same id for all entries ...by changing the first line back to  `{% set relatedMarket = entry.market.first() %}.  Dump now depicts the correct category id for each entry. But I am still stuck - and again this approach works and still works on another site.
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-23T16:48:20.693Z
Comments.Text: @AbbeyDesign , sorry I can't tell where you are suggesting I try adding a space?
Comments.UserDisplayName: Hellyar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-23T16:49:20.623Z
Comments.Text: I think there should be a space after "not".... 'not '
Comments.UserDisplayName: AbbeyDesign
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-23T16:56:08.197Z
Comments.Text: @AbbeyDesign  THANK YOU!!!,  And this is why people with geo-political backgrounds should not try coding.  The missing space after `not ` was the culprit.  OMG!!!  How do I get this out of the comment so you get credit for the answer?
Comments.UserDisplayName: Hellyar
Tags: <categories>
Title: Related Items in a Category not Appearing in Results
ThreadText: # Related Items in a Category not Appearing in Results
  
  (Asked by: username_0 on 2016-08-22)
  
  I am still having a problem looping through related posts.
  
  I get zero, not even the HTML. And there are no Craft template errors. There are plenty of entries that were assigned the same market, so there should be something. AND this exact approach worked perfectly before !@$!@#!
  
  ```
  <h5>Similar Projects</h5>
  
  {% set relatedMarket = entry.market.first() %}
  {% set relatedEntries = craft.entries.section('posts').relatedTo({ targetElement: relatedMarket, field: 'market'}).id('not'~entry.id) %}
  
  {% for relatedEntry in relatedEntries %}
      <a href="{{ relatedEntry.url }}"><p> Entry title goes here. {{ relatedEntry.title  }} </p></a>
  {% endfor %}    
  
  ```
  
  I double checked. My entry section handle is `posts`. The handle for the `posts` entry type is `notifications`. The category group handle is `markets`. The category entry field handle is `market`. I included the entry type and category group handles just in case I am missing something.
  
  **Tags:** categories
  
  > **Comments:**
  > **username_1**: Are you getting any HTML on the page or is it totally blank? Are you in `devMode`?  
  > **username_0**: I am in devMode.  The rest of the page is working.  The layout is extended.  The entry title, image, body, and category all appear.  This section, however, generates nothing.  I stripped out the reference to the 'owl carousel` and stripped my example to print just the `relatedEntry.title` and `relatedEntry.url`.  It still is generating nothing.  
  > **username_0**: {% set relatedMarket = entry.market.first() %}    {% set relatedEntries = craft.entries.section('posts').relatedTo(    { targetElement: relatedMarket, field: 'market'}).id('not'~entry.id) %}    {% for relatedEntry in relatedEntries %}     <a href="{{ relatedEntry.url }}"><p> {{ relatedEntry.title  }} </p></a>    {% endfor %}  
  > **username_2**: You could try dumping each variable to debug using `{{ dump( relatedMarket ) }}` or simply see if anything has been found by applying the `length` filter like so: `{{ relatedEntries|length }}`. What is the `length` of `relatedEntries`?  
  > **username_0**: `{{ relatedEntries|length }}` printed nothing. `{{ dump( relatedMarket) }}` printed, but I can't decipher it.  
  > **username_2**: Try using `{% set relatedMarket = craft.categories.id( entry.market.id ).first() %}`  
  > **username_3**: Start by making sure you're getting the relatedMarket you think you are. If you `{{ dump(relatedMarket.id }}`, is that the correct market ID you'd expect in the control panel?  
  > **username_0**: I added `{{ dump(relatedMarket.id) }}` every entry returns the same `string(1) "4"` - even those with a different selection from the `market` field.  
  > **username_0**: Sorry a bit new...  `{{ dump(relatedMarket.id)}}` is showing the same `id` for all entries, even though that is not the case.  
  > **username_0**: And even entries with id "4" assigned print nothing.  
  > **username_3**: OK, work backwards from there.  Is `{{ dump(entry.id) }}` the one you think it is? Also it sounds like you've got entry in a loop?  
  > **username_0**: `{{ dump(entry.id) }}`  a sample result is `string(2) "42"`or `string(1) "3"`,  the second # corresponds to an entry's `id`.   I am not sure what the (2) or (1) denotes.   But, of the 11 test entries all but one is (2).  
  > **username_0**: So, to put another way...  what am I looking for?   I am confused.   `{{ dump(relatedMarket.id) }}` shows everything to be `(1)"4"`.  If I assume this is a reference to the `category group id` and 'category id' then something seems off.  The reported `category group id` is correct, but different `category id` should be appearing across the test entries.  
  > **username_4**: Shouldn't .id('not'~entry.id) have a space in it? .id('not '~entry.id)  
  > **username_0**: I was able to address dump(relatedMarket) depicting the same id for all entries ...by changing the first line back to  `{% set relatedMarket = entry.market.first() %}.  Dump now depicts the correct category id for each entry. But I am still stuck - and again this approach works and still works on another site.  
  > **username_0**: @username_4 , sorry I can't tell where you are suggesting I try adding a space?  
  > **username_4**: I think there should be a space after "not".... 'not '  
  > **username_0**: @username_4  THANK YOU!!!,  And this is why people with geo-political backgrounds should not try coding.  The missing space after `not ` was the culprit.  OMG!!!  How do I get this out of the comment so you get credit for the answer?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2016-08-23. Score: 4 | Accepted answer
  
  The code above was missing a space after not
  
  `.id('not'~entry.id)` should have been `.id('not '~entry.id)`
  
  This one is an easy one to miss and I have done it a million times.
  
  
  ---
  
  