Dataview query author's work where there are multiple authors in frontmatter of a work

Things I have tried

I have file for every author and a file for every book. In book file, there is ‘author’ variable in front matter; in author file I have dataview querying all works by author, which works fine

dv.table(["Title", "Published", "Pages"], dv.pages()
.sort(t => t.year, 'asc')
.where(t => t.author == dv.current().file.name)
.map(t => [t.file.link, t.year, t.pages]))

What I’m trying to do

Problem happen when a book has multiple author… I wish to display on author’s file books having multiple co authors where author contributed. I tried ‘include’ or ‘contains’ with dataviewjs, documentation online is confusing, syntax don’t work in obisidian. I tried the code below. Thank for help

dv.table(["Title", "Published", "Pages"], dv.pages()
.sort(t => t.year, 'asc')
.where(t => t.author.includes(dv.current().file.name))
.map(t => [t.file.link, t.year, t.pages]))

First thing to clarify:

  • How you write your author field values? What’s the syntax? It’s a list or a string with multiple names?

Hello,

In YAML frontmatter it is written for single authors and works fine:

author: George Orwell

For multiple authors:

author:
 - Raghuram Rajan 
 - Luigi Zingales

But on this I willing to use any format; for example I experimented with

author: ["Raghuram Rajan", "Luigi Zingales"]

Willing to use whatever format works for my purpose. Thank.

And if you change

.where(t => t.author.includes(dv.current().file.name))

to

.where(t => t.author?.includes(dv.current().file.name))

(but this works only if all author values are strings… if, for example, a link, all query fails)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.