On my template I am showing detail of an entry. Beneath this I am showing a list of other entries that share the same kind of category relationship as the entry being viewed.

This list currently includes the entry being viewed and I wish to omit that from the list.

I'm retrieving the entries like so:

{% for category in craft.entries.section('apprenticeshipsCats').relatedTo(entry).id('not ' ~ entry.id) %}

and had expected the 'not' parameter to do what I wanted but it doesn't seem to be working. entry.id is outputting the correct ID and even if I hardcode the entry id then it still appears in the list.

  • Do you want to list entries from your "apprenticeships" or "apprenticeships categories" section? – carlcs Oct 16 '15 at 8:54
  • I'm listing entries from the apprenticeships channel. It's all working fine except for being able to omit the apprenticeship entry which is currently viewed. – foamcow Oct 16 '15 at 12:15
  • Ha! I'd actually done it correctly but applied by 'not' criteria to the wrong craft.entries loop. Like an idiot. I'm so amateur! – foamcow Oct 16 '15 at 12:25
  • Like I said, wrong section. Compare the solution in your update to what I posted. You notice something? – carlcs Oct 16 '15 at 13:01

You probably kind of confuse your "apprenticeships categories" with your "apprenticeships" section. Try something like this instead:

{% set relatedEntries = craft.entries({
    section: apprenticeships,
    id: 'not ' ~ entry.id,
    relatedTo: {
        targetElement: entry.apprenticeshipsCatsField
}) %}

You now want to order them by your categories? Have a look at my answer I just posted here: "How do I display entries, grouped by distinct categories...".

| improve this answer | |
  • No. It was a different problem. Combined with a late night and rushing to get something done before I went out I was working with the wrong bit of the template. My original idea worked once I'd put it in the correct place. – foamcow Oct 16 '15 at 12:26
  • Different problem? Changing "apprenticeshipsCats" to "apprenticeships" (or "vacancies" – I didn't know your channel handle) looks like exactly what you did in the end?! – carlcs Oct 16 '15 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.