Hi,
I’ve created an author metaboject with simple details (Name, photo, and a short bio). I intend to add a metafield to blog posts which allows selection of a metaobject. This way, I can link each blog post to an author bio.
However, on the author metaobject template itself, I’d like to display a list of blog posts that has the current author metaobject assigned to it so that it shows a nice list of articles contributed by the current author. What’s the best way to achieve this?
Many thanks,
S
For development blogs have articles not posts.
AFAIK , off the top of my head no testing, there’s no reference chain you could follow to get those articles exclusively through the metaobject using only liquid.
You’d want to tag those articles then get then have logic to go over all artilcles outputting any with the matching tags, or tag-filtered-blog articles with ajax on the client-side.
You cannot tag-filter a resources objects internally using tags inside liquid i.e. no {% assign articles = blogs[‘news/tagged/tagname+tagname2’].articles %}
Or setup some automation to add those articles as references to the author metaobject itself.
No pre-existing thing for this scenario but mechanic has some tag-to-metafield examples https://tasks.mechanic.dev/copy-prefixed-tags-to-metafields
Hey Paul,
Actually, I think you’re overthinking it. I just got it to work with a simple solution. I created a section that I can use within the metafields template. The code within that section is as follows:
{% assign current_author = metaobject.full_name.value %}
{% for article in blogs['content'].articles %}
{% assign article_meta = article.metafields.custom.author_profile.value %}
{% assign article_author = article_meta.full_name %}
{% if article_author == current_author %}
{{ article.title }}
{% endif %}
{% endfor %}
So basically the code is comparing the currently loaded metaobject’s against all the articles to see if the metafield in those article have a matching metaobject assigned to them. 
2 Likes
Good work , of course if there’s a manual metafield on the articles you don’t need checks based on tags, which is still a check. This does mean on the client-side having to use storefront-filtering instead of tag-based-filtering for customers navigation & search of blogs and articles. And a bit more complication to group authors.
If there’s a single reference property on the articles you may be able to use the where, or map, filters and skip loops.
https://shopify.dev/docs/api/liquid/filters/where
https://shopify.dev/docs/api/liquid/filters/map
Either way test for pagination behavior when over 50 articles.
Good Hunting.
1 Like