I am trying to fetch all the blog authors with blog_authors(“default”, 250) function, but this is only returning 3 authors. I am using that in a module. Here is my full code.
{{ blog_authors("default", 20) }}
{% set my_authors = blog_authors("default", 250) %}
<ul>
{% for author in my_authors %}
<li><a href="{{ blog_author_url(group.id, author.slug) }}">{{ author }}</a></li>
{% endfor %}
I also tried this with Hubspot CMS Api which is returning the correct result. I am attaching a screenshot of the result here.
I was trying to do the same thing. However, it seems unique / union doesn’t work. Maybe there is some kind of underlying object which is preventing it from detecting same author from different blog.
So, the issue is that John Smith author on blog A and John Smith author on blog B are unique.
If you look at the JSON it spits out, it’s the livePosts value that causes the issue.
Here’s a simplified version of adding the Author names to an array if it’s unique:
{% set my_authors1 = blog_authors(34471392197, 250) %}
{% set my_authors2 = blog_authors(59761752650, 250) %}
{% set all_authors = (my_authors1 + my_authors2)|sort(False, False, "display_name") %}
{% set unique_authors = []%}
{% for author in all_authors %}
{% unless author.display_name in unique_authors %}
{% do unique_authors.append( author.display_name ) %}
{% endunless %}
{% endfor %}
Now that’s simply just an array of their names. If you want the other author info it’s going to get more complicated.
I tried playing around with
{% unless author.display_name in unique_authors|??????? %}
{% do unique_authors.append( author ) %}
{% endunless %}
trying to figure out how to search inside the nested arrays of the unique_authors array using attr and the like but I’m not coming up with anything.