<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>

CC BY-SA 3.0
2016-08-23T17:04:10.717Z
2016-08-23T18:45:02.700Z
2016-08-23T18:45:02.700Z
AbbeyDesign
<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>

CC BY-SA 3.0
2016-08-22T13:49:13.323Z
Are you getting any HTML on the page or is it totally blank? Are you in `devMode`?
Aaron Berkowitz
CC BY-SA 3.0
2016-08-22T14:16:06.920Z
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.
Hellyar
CC BY-SA 3.0
2016-08-22T14:16:29.593Z
{% 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 %}
Hellyar
CC BY-SA 3.0
2016-08-22T14:54:48.283Z
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`?
Luke Pearce
CC BY-SA 3.0
2016-08-22T15:15:26.140Z
`{{ relatedEntries|length }}` printed nothing. `{{ dump( relatedMarket) }}` printed, but I can't decipher it.
Hellyar
CC BY-SA 3.0
2016-08-22T16:32:13.613Z
Try using `{% set relatedMarket = craft.categories.id( entry.market.id ).first() %}`
Luke Pearce
CC BY-SA 3.0
2016-08-22T20:51:40.323Z
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?
Brad Bell
CC BY-SA 3.0
2016-08-22T20:58:37.087Z
I added `{{ dump(relatedMarket.id) }}` every entry returns the same `string(1) "4"` - even those with a different selection from the `market` field.
Hellyar
CC BY-SA 3.0
2016-08-22T21:03:13.187Z
Sorry a bit new...  `{{ dump(relatedMarket.id)}}` is showing the same `id` for all entries, even though that is not the case.
Hellyar
CC BY-SA 3.0
2016-08-22T21:06:02.963Z
And even entries with id "4" assigned print nothing.
Hellyar
CC BY-SA 3.0
2016-08-22T22:15:22.743Z
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?
Brad Bell
CC BY-SA 3.0
2016-08-22T23:13:33.497Z
`{{ 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).
Hellyar
CC BY-SA 3.0
2016-08-22T23:22:38.270Z
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.
Hellyar
CC BY-SA 3.0
2016-08-23T16:44:06.383Z
Shouldn't .id('not'~entry.id) have a space in it? .id('not '~entry.id)
AbbeyDesign
CC BY-SA 3.0
2016-08-23T16:44:11.740Z
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.
Hellyar
CC BY-SA 3.0
2016-08-23T16:48:20.693Z
@AbbeyDesign , sorry I can't tell where you are suggesting I try adding a space?
Hellyar
CC BY-SA 3.0
2016-08-23T16:49:20.623Z
I think there should be a space after "not".... 'not '
AbbeyDesign
CC BY-SA 3.0
2016-08-23T16:56:08.197Z
@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?
Hellyar
<categories>
Related Items in a Category not Appearing in Results
# 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 !@$!@#!
Similar Projects

{% set relatedMarket = entry.market.first() %}
{% set relatedEntries = craft.entries.section('posts').relatedTo({ targetElement: relatedMarket, field: 'market'}).id('not'~entry.id) %}

{% for relatedEntry in relatedEntries %}
     Entry title goes here. {{ relatedEntry.title  }} 
{% 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**: @AbbeyDesign , 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**: @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?  

---

## 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.


---

