Support Log in
AI Custom Fields Builder

Headless WordPress Custom Fields Guide

In headless WordPress, WordPress is the CMS (for content editing) and a JavaScript framework such as Next.js, Astro, Nuxt or SvelteKit renders the frontend. Custom fields are not part of the core API, so the frontend needs a way to read them. This guide shows how Field Forge exposes them (REST, WPGraphQL and generated TypeScript types) and gives example setups.


Part 1: Headless WordPress

In traditional WordPress one PHP stack handles content editing and renders the pages. In headless WordPress, WordPress handles content editing and data storage, and a separate JavaScript frontend reads the content through an API (REST or GraphQL) and renders the pages.


Part 2: Custom fields in headless WordPress

Custom fields are defined by plugins, not by WordPress core, so the frontend does not know their names or types unless a plugin describes them. Field Forge Pro generates TypeScript definitions and GraphQL SDL from your field groups, and the free plugin adds the field values to core REST responses (the fieldforge property).


Part 3: How Field Forge solves headless WordPress custom fields

Field Forge has these headless features.

Storing values in a custom table

Instead of wp_postmeta, Field Forge stores field values in a dedicated indexed table. get_field() reads a post’s top-level values with one query and caches them with the WordPress object cache API, which helps when the frontend fetches content from WordPress on every build (or every request for SSR).

Custom table storage feature →

TypeScript type generation

With Pro, Field Forge generates .d.ts TypeScript definitions for your field groups. Download the file and commit it to your frontend repo:

import type { HeroSectionFields } from '@/types/fieldforge';

function Hero({ data }: { data: HeroSectionFields }) {
  return <h1>{data.hero_title}</h1>;  // TypeScript autocomplete + error checking
}

The types are made when you press Generate TypeScript. Run it again after you edit field groups.

TypeScript generation feature →

Native WPGraphQL integration

When Field Forge and WPGraphQL are both active, Pro registers its GraphQL types with WPGraphQL. The custom fields can then be queried:

query GetPage {
  page(id: "home", idType: URI) {
    title
    fieldforge {
      heroSection {
        title
        subtitle
        backgroundImage { sourceUrl }
      }
    }
  }
}

No separate WPGraphQL for ACF plugin needed.

GraphQL generation feature →

REST API with inline custom fields

Field Forge exposes custom field values on core REST endpoints under a fieldforge property:

GET /wp-json/wp/v2/posts/123

{
  "id": 123,
  "title": { "rendered": "Our Services" },
  "fieldforge": {
    "service_list": [
      { "name": "Web Design", "description": "..." },
      { "name": "SEO", "description": "..." }
    ]
  }
}

One API call returns the post and its custom fields.

Schema synchronization via Local JSON

Field Forge’s Local JSON Sync saves field groups as JSON files in your uploads folder. Commit to git. Deploy across environments. Deploy the same files to dev, staging and production and sync them there.


Part 4: Next.js + Field Forge setup

Here is a setup guide for Next.js with Field Forge.

Install WordPress with Field Forge

  1. Install WordPress (traditional or managed host)
  2. Install Field Forge (free version on WordPress.org is fine for testing)
  3. Create field groups in Field Forge for your content types

Install Next.js frontend

npx create-next-app@latest my-headless-site --typescript --app
cd my-headless-site

Create a WordPress API client

Create lib/wordpress.ts:

const WP_API_URL = process.env.WP_API_URL || 'https://wp.example.com/wp-json';

export async function fetchPost(slug: string) {
  const res = await fetch(`${WP_API_URL}/wp/v2/posts?slug=${slug}`);
  const posts = await res.json();
  return posts[0];
}

export async function fetchPage(slug: string) {
  const res = await fetch(`${WP_API_URL}/wp/v2/pages?slug=${slug}`);
  const pages = await res.json();
  return pages[0];
}

Import Field Forge TypeScript types

Generate and download the .d.ts file in Field Forge admin (Pro): Field Forge → Tools → Headless Types → Generate TypeScript → Download.

Save to types/fieldforge.d.ts:

export interface WPImage {
  ID: number;
  url: string;
  width: number;
  height: number;
  alt: string;
  title: string;
  sizes: Record<string, string>;
}

export interface HeroSectionFields {
  title: string;
  subtitle: string;
  background_image: WPImage;
  cta_button: {
    text: string;
    url: string;
  };
}

export interface PageWithFields {
  id: number;
  title: { rendered: string };
  fieldforge: {
    hero_section?: HeroSectionFields;
  };
}

Create a page component

app/[slug]/page.tsx:

import { fetchPage } from '@/lib/wordpress';
import type { PageWithFields, HeroSectionFields } from '@/types/fieldforge';

export default async function Page({ params }: { params: { slug: string } }) {
  const page: PageWithFields = await fetchPage(params.slug);

  return (
    <main>
      <h1>{page.title.rendered}</h1>

      {page.fieldforge.hero_section && (
        <Hero data={page.fieldforge.hero_section} />
      )}
    </main>
  );
}

function Hero({ data }: { data: HeroSectionFields }) {
  return (
    <section className="hero">
      <img
        src={data.background_image.url}
        alt={data.background_image.alt}
      />
      <h2>{data.title}</h2>
      <p>{data.subtitle}</p>
      <a href={data.cta_button.url}>{data.cta_button.text}</a>
    </section>
  );
}

That’s a minimal Next.js + Field Forge setup. With the generated types, the build fails when a property name is misspelled.

Static generation with generateStaticParams

For static site generation, fetch all pages at build time:

export async function generateStaticParams() {
  const res = await fetch(`${WP_API_URL}/wp/v2/pages`);
  const pages = await res.json();

  return pages.map((page: any) => ({
    slug: page.slug,
  }));
}

Next.js will pre-render every page as static HTML at build time.


Part 5: Astro + Field Forge setup

Here is a setup guide for Astro with Field Forge.

Create Astro project

npm create astro@latest my-site
cd my-site

Fetch WordPress content

Create src/lib/wordpress.ts:

const WP_API_URL = import.meta.env.WP_API_URL;

export async function getPages() {
  const res = await fetch(`${WP_API_URL}/wp/v2/pages`);
  return res.json();
}

export async function getPageBySlug(slug: string) {
  const res = await fetch(`${WP_API_URL}/wp/v2/pages?slug=${slug}`);
  const [page] = await res.json();
  return page;
}

Page with Field Forge types

src/pages/[slug].astro:

---
import { getPages, getPageBySlug } from '@/lib/wordpress';
import type { PageWithFields } from '@/types/fieldforge';
import Hero from '@/components/Hero.astro';

export async function getStaticPaths() {
  const pages = await getPages();
  return pages.map((page: any) => ({
    params: { slug: page.slug },
    props: { page },
  }));
}

const { page } = Astro.props as { page: PageWithFields };
---

<html>
  <body>
    <h1 set:html={page.title.rendered} />

    {page.fieldforge.hero_section && (
      <Hero data={page.fieldforge.hero_section} />
    )}
  </body>
</html>

With static generation, Astro fetches the content from the REST API once, at build time, and writes static HTML.


Part 6: Nuxt + Field Forge setup

Here is a setup guide for Nuxt (Vue) with Field Forge.

Create Nuxt project

npx nuxi@latest init my-site
cd my-site

Nuxt server route

server/api/page/[slug].get.ts:

export default defineEventHandler(async (event) => {
  const { slug } = getRouterParams(event);
  const config = useRuntimeConfig();

  const response = await $fetch(
    `${config.wpApiUrl}/wp/v2/pages?slug=${slug}`
  );

  return response[0];
});

Vue page component

pages/[slug].vue:

<template>
  <main v-if="page">
    <h1 v-html="page.title.rendered"></h1>

    <Hero v-if="page.fieldforge.hero_section" :data="page.fieldforge.hero_section" />
  </main>
</template>

<script setup lang="ts">
import type { PageWithFields } from '@/types/fieldforge';

const route = useRoute();
const { data: page } = await useFetch<PageWithFields>(`/api/page/${route.params.slug}`);
</script>

Part 7: SvelteKit + Field Forge

For Svelte fans:

// src/routes/[slug]/+page.server.ts
import type { PageServerLoad } from './$types';
import type { PageWithFields } from '$lib/types/fieldforge';

export const load: PageServerLoad = async ({ params, fetch }) => {
  const res = await fetch(`${WP_API_URL}/wp/v2/pages?slug=${params.slug}`);
  const pages = await res.json();
  const page: PageWithFields = pages[0];

  return { page };
};
<!-- src/routes/[slug]/+page.svelte -->
<script lang="ts">
  import type { PageData } from './$types';
  import Hero from '$lib/components/Hero.svelte';

  export let data: PageData;
</script>

<h1>{@html data.page.title.rendered}</h1>

{#if data.page.fieldforge.hero_section}
  <Hero data={data.page.fieldforge.hero_section} />
{/if}

Part 8: GraphQL approach (WPGraphQL + Field Forge)

For deep nested queries, you can use GraphQL instead of REST:

Install WPGraphQL

  1. WordPress admin → Plugins → Add New → search “WPGraphQL”
  2. Install and activate
  3. Pro adds GraphQL types when WPGraphQL is active

Query in Next.js

async function fetchHomepage() {
  const query = `
    query GetHomepage {
      page(id: "home", idType: URI) {
        title
        fieldforge {
          heroSection {
            title
            subtitle
            backgroundImage {
              sourceUrl
              altText
            }
            ctaButton {
              text
              url
            }
          }
        }
      }
    }
  `;

  const res = await fetch(`${WP_API_URL}/graphql`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ query }),
  });

  const { data } = await res.json();
  return data.page;
}

One request fetches the page and its custom fields.


Frequently asked questions

Should I use REST or GraphQL with headless WordPress?

Depends on the frontend and complexity. REST needs no extra plugin. GraphQL needs WPGraphQL and can ask for deeply nested data in one query. For small sites, REST. For sites with complex content structures, GraphQL.

How do I handle previews in headless WordPress?

Preview is one of the hardest parts of headless. Options: Next.js preview mode (fetches draft content with a secret token), Gatsby’s preview plugin, or custom WordPress → frontend webhook triggers.

How often should I rebuild my static site?

Depends on content update frequency. For daily-updated content, nightly builds. For less frequent updates, webhook-triggered builds (WordPress publishes a post → webhook triggers a build).

Can I edit content through the headless frontend?

Yes, via the WordPress REST API or WPGraphQL mutations. Editors can also keep working in the WordPress admin while the frontend only reads.

How do I handle forms in headless WordPress?

Options: 1) Fillin Forge posts to WordPress REST API, 2) Third-party form service (Formspree, Netlify Forms), 3) Direct API integration with form services. For most cases, Fillin Forge + REST API is the simplest.

What about media uploads?

Headless frontends typically still use WordPress’s media library for storage. The frontend fetches image URLs from API responses. For user-uploaded content, POST to WordPress’s media REST endpoint.


Ready to build headless WordPress with Field Forge?

See pricing →

Free version includes 31 field types, the visual builder, Local JSON sync, and field values on the WordPress REST API. Paid plans add TypeScript and GraphQL generation, WPGraphQL types and the rest of the headless tooling.

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs