'How to filter Sanity posts by category title?

Here what I've done in vision

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

It returned

No documents found in dataset production that match query:


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


Solution 1:[1]

You have to format it like so:

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

If nothing shows up then there are no posts associated with that category. Categories are also case sensitive, so make sure your capitalization is right.

Solution 2:[2]

*[_type == "post" &&  "social" in categories[]->title]{
title
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brandon Pyle
Solution 2 cmcollin41