【问题标题】:How to filter Sanity posts by category title?如何按类别标题过滤 Sanity 帖子?
【发布时间】:2022-01-18 09:58:03
【问题描述】:

这是我在视觉中所做的事情

*[_type == "post" && categories == SOCIAL ]{
  _id, title
}

返回

No documents found in dataset production that match query:


*[_type == "post" && categories == SOCIAL ]{
  _id, title
}

【问题讨论】:

  • categories 是可以包含字符串"SOCIAL" 的数组吗?如果是这样,您必须使用in*[_type == "post" && "SOCIAL" in categories]
  • @AlexanderStaubo 在数据集生产中找不到与查询匹配的文档:*[_type == "post" && "SOCIAL" in categories]
  • categories 是字符串数组吗?
  • @AlexanderStaubo "result":[8 items 0:{6 items "_createdAt":"2021-12-15T05:14:53Z" "_id":"167d5d3e-ce1b-4f0c-a092- aa81213bed41" "_rev":"wY9KfPeCwmcMrJtIpsqdOq" "_type":"category" "_updatedAt":"2021-12-15T05:14:53Z" "title":"SOCIAL" }
  • 所以它不是一个字符串数组。你需要这样写:"SOCIAL" in categories[].title。但是,如果categories 是一个引用数组,则需要这样编写:"SOCIAL" in categories[]->title

标签: sanity groq


【解决方案1】:

你必须像这样格式化它:

*[_type == "post" && categories == "SOCIAL" in categories[]->title]{
  title,
  slug,
  body
}

如果没有显示,则没有与该类别相关的帖子。类别也区分大小写,因此请确保您的大小写正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-12
    • 2021-10-26
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多