Dataview query for specific tag in folder; tags not working and siomplified query only returns 1/2 of files in directory

What I’m trying to do

I am struggling to get a basic dataview query working.

I want to build a simple list of all the files in/beneath a directory with a specific tag.

For reference, the queries that I am trying to get working are inside the file / that is where I want the list generated.

There are only two .md files in the directory and of the two, only the some title has the worklog as a tag.

The dataview query should return only one result: some title here.

Here’s how things look on disk:

❯ cd $vaultRoot/Path/Example/Here
❯ tree .
├── _files
│ └── <a bunch of things that are not important here>
├── some title

# Now lets take a look at the file that has the tag of interest
❯ head some\ title\

  - some-title-here

  - some
  - things/that/dont/matter
  - worklog

created: 2022-10-...
modified: 2022-10-...

FileContentHere ...

Things I have tried

In the I have tried:

FROM "Path/Example/Here"
WHERE contains(tags, "worklog")

This returns NOTHING.

FROM "Path/Example/Here" and "#worklog"

This returns NOTHING.

FROM "Path/Example/Here" and "worklog"

This returns NOTHING.

But here’s the odd bit. THIS QUERY:

FROM "Path/Example/Here"

returns one result:

See the tree output above… there are TWO files in the Path/Example/Here directory!

Up until that last query, I wasn’t sure that tags done in front matter like i’ve done were supported… but this GH issue seems to imply that they are supported and the queries SHOULD work:

But the query with a basic “from $folder” returning only 1/2 of the folder content makes me think that something more fundamental is broken / wrong.

Hi @cabin.mooring ,

At first look, I’m not sure where the problem is. I did the following and it worked for me:

  • Opened the Sandbox vault and set to Light theme
  • Installed Dataview
  • Created a page with a query to get everything from the “Adventurer” directory:

Then I:

  • Added a few tags to the “No Prior Experience” page
  • Added the tag to the query:

The only difference I see now is that in your DQL you use

FROM "Path/Example/Here" and "#worklog"

when it should be no quotes around the tag:

FROM "Path/Example/Here" and #worklog

I hope this is helpful.


1 Like

That worked.

I could have sworn up and down that I tried w/o quotes.
Literally nothing has changed in my vault (w/r/t plugins and the like).
I have restarted my computer since posting this so of course obsidian has been restarted.

I don’t know what to say… maybe I did forget to drop the quotes!

In dataview queries, it is file.tags - see here

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