Random posts displayed but exclude current entry ID I am brand new to Craft and can't find much support on this problem online. I have my entry pages and at the bottom of them, I have a div with the code below in it which randomly links to any entry.

I now would like this to disallow the entry that I am on from that randomization. I assume from other threads it would be something to do with finding the ID of the entry the user is on and not allowing it in the randomize?

{% for image in randomEntry.projectFeaturedImage %}

    &lt;a href="{{ randomEntry.url }}"&gt;{{ randomEntry.title }}&lt;/a&gt;
    &lt;a href="{{ randomEntry.url }}"&gt;See Project&lt;/a&gt;

{% endfor %}
Here are a couple of useful stackexchange questions


Getting a random entry: Section entries - order by random
Excluding the current entry: Exclude Current Entry


Putting that together:

{% set randomEntry = craft.entries({
  id: 'not '~entry.id,
  order: 'RAND()'
}).first %}


This will fetch entries whose id is not entry.id (entry is the current entry), ordered randomly, and then give you the first of those.

Probably you want to specify the section or sections to fetch your entries from:

{% set randomEntry = craft.entries({
  section: ['thisSection', 'thatSection', 'theOtherSection'],
  id: 'not '~entry.id,
  order: 'RAND()'
}).first %}


This will do the same thing, but only fetch entries from those 3 sections.

After all of that, you should also be sure to test that there actually is an entry:

{% if randomEntry %}
  ... do your thing ...
{% endif %}