Surf the DreamJustin Avery

Snippets, Wordpress

Retrieving Wordpress Menus using GraphQL

TypeScript
import React from "react"
import { graphql } from "gatsby"

const primaryMenu = ({ data }) => <pre>{JSON.stringify(data, null, 4)}</pre>

export const query = graphql`
  {
    menu(id: "PRIMARY", idType: NAME) {
      menuItems {
        nodes {
          key: id
          parentId
          title: label
          url
          description
          cssClasses
        }
      }
    }
  }
`

export default primaryMenu

Comments

Be the first to comment

Comments are read before they appear. Your email address is never shown.

    Type to search titles and full text. ↵ opens the full results page.