entry.getAuthor().getGroups() always return empty array I'm trying to output users groups for every entries in a for loop, but it returns an empty array:

{%for entry in craft.entries.section('news') %}
    ...
    {{ dump(entry.getAuthor().getGroups()) }}
{% endfor %}


But it's working correctly in the entry page itself.

Any idea how I can return the groups in a for loop?
I spot a couple of Twig errors in your code.

First, in your for loop you're casting the entries returned by craft.entries to a variable news, but you're calling entry.getAuthor() inside the loop. Either change news to entry or entry to news.

Second, I'm not sure if craft.entries('news') actually returns anything (or at least not what you actually want) – it should probably be craft.entries.section('news').

Putting it together, this should work:

{% for entry in craft.entries.section('news') %}
    ...
    {{ dump(entry.getAuthor().getGroups()) }}
{% endfor %}


Also, since you're not reporting any error messages output by Craft, I'm guessing you haven't enabled devMode in your development environment. It's a really good idea to have devMode set to true while you're working on your code, because then Craft will report any syntax errors (like your undeclared entry variable) which will make it way easier for you to debug.

Just remember to never have devMode enabled for production environments – it's both a performance and security issue if you do.