I am trying to do the following with craft.entries but I think it may not be possible without a plugin.
I have 9 categories with related entries on all of them. I would like to get the latest articles (postDate) for each one the categories and then group by category and only show only the seven latest articles, one for each category.
The following works but it fetches 100 articles each time (I can reduce it but still its not ideal)
{% set latestArticles = craft.entries.section('articles').relatedTo({element: selectedCategories, field: 'journalismMainCategory'}).order('postDate desc').find() %}
{% set groupedArticles = latestArticles|group('journalismMainCategory.first.id')|slice(0,7) %}
I've also tried the following but I cannot get it to sort by date or group the category properly. It retrieves the latest article for each category, but in the order of the category (and not by post date)
{% set selectedCategories = [98, 100, 2412, 2408, 2410, 2414, 2416, 55332, 55333] %}
{% for category in selectedCategories %}
{% set stilesArticles = stilesArticles|merge([craft.entries.section('articles').relatedTo({element: selectedCategories[loop.index0], field: 'journalismMainCategory'}).limit(1).first]) %}
{% endfor %}
Any ideas on how something like this can be done without a plugin?
Cheers!