Frequently asked questions

By Knut Melvær

Simple content type for a question and answer pattern

faq.js

// faq.js
export default {
  name: 'faq',
  type: 'object',
  title: 'Frequently asked question',
  fields: [
    {
      name: 'question',
      type: 'string',
      title: 'Question'
    },
    {
      name: 'answer',
      type: 'text',
      title: 'Answer',
    }
  ]
}

Help article

// helpArticle.js
export default {
  name: 'helpArticle',
  type: 'document',
  title: 'Help article',
  fields: [
    {
      name: 'title',
      type: 'string',
      title: 'Title'
    },
    {
      name: 'faqs',
      type: 'array',
      title: 'Frequently Asked Questions',
      of: [
        {
          type: 'faq'
        }
      ]
    }
  ]
}

schema.js

// First, we must import the schema creator
import createSchema from 'part:@sanity/base/schema-creator';

// Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type';

// other imports
// ...
import faq from './faq'

export default createSchema({
  name: 'default',
  types: schemaTypes.concat([
    // ... other types,
    faq
  ])
})

If you import this schema into schemas.js, then you can use this pattern as type: 'faq' elsewhere.

Contributor

Other recipes by the contributor

First Published Timestamp Function

Featured contribution
Official(made by Sanity team)

Automatically track when content was first published with a timestamp that sets once and never overwrites, providing reliable publication history for analytics and editorial workflows.

Knut Melvær
Go to First Published Timestamp Function

Automatically tag blog posts

Featured contribution
Official(made by Sanity team)

AI-powered automatic tagging for Sanity blog posts that analyzes content to generate 3 relevant tags, maintaining consistency by reusing existing tags from your content library.

Go to Automatically tag blog posts