Skip to content

Most related entries #13161

Answered by mmikkel
HannahDeWachter asked this question in Q&A
May 5, 2023 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

The Similar plugin could be helpful for your use case:

{% set categories = entry.catergoryA.ids()|merge(entry.catergoryB.ids())|merge(entry.catergoryC.ids()) %}
{% set news = craft.similar.find({ element: entry, context: categories, criteria: craft.entries.section('news').limit(4) }) %}

With the above, the news variable would be an array of (maximum 4) entries related to the category IDs from those three category fields; automatically sorted by the number of relations (the entries will also have an additional count attribute, referencing the total number of relations for each entry).

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@HannahDeWachter
Comment options

@HannahDeWachter
Comment options

Answer selected by HannahDeWachter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants