npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

acf-generator

v0.0.6

Published

Strongly typed ACF PHP code generator

Downloads

13

Readme

acf-generator

A php code generator for WordPress Advanced Custom Fields (ACF).

Installation

Install via npm or yarn:

npm install acf-generator
# or
yarn add acf-generator

Basic Usage

1. Define Your Fields

Define fields using the createField utility. Compose single fields or nested structures:

import { createField } from "acf-generator";

export const heroHomeFields = createField({
  type: "group",
  label: "Hero Home",
  name: "hero_home",
  sub_fields: [
    {
      type: "text",
      name: "title",
      label: "Title",
    },
    {
      type: "textarea",
      name: "text",
      label: "Text",
    },
    {
      type: "link",
      name: "cta",
      label: "CTA",
    },
  ],
});

2. Create a Field Group

Generate the group and its PHP registration code with createGroup:

import { createGroup } from "acf-generator";
import { heroHomeFields } from "./components/heroHome.astro";

export const { registerCode: registerFrontPage, phpVars } = createGroup({
  key: "front_page",
  title: "Home Settings",
  fields: [
    heroHomeFields,
  ],
  hide_on_screen: ["the_content"],
  location: [
    [
      {
        param: "page_type",
        operator: "==",
        value: "front_page",
      },
    ],
  ],
}).getCode();

export const { registerCode: registerOptions, phpVars: optionsPhpVars } = createGroup({
  key: "global_theme_options",
  title: "Theme Settings",
  fields: [
    // you can also define a field without createField
    {
      label: "Footer Note",
      name: "footer_note",
      type: "link",
    }
  ] as const,
  location: [
    [
      {
        param: "options_page",
        operator: "==",
        value: "theme-options",
      },
    ],
  ],
  // first argument will be passed as $post_id to [get_field](https://www.advancedcustomfields.com/resources/get_field/)
}).getCode("options");

3. Register Fields in Templates

With astro-wordpress, you can register the generated fields inside functions.php.astro or a .php.astro file and include it in your functions.php:

---
import { registerCode as registerFrontPage } from "./front-page.php.astro";
import { registerCode as registerOptions } from "./acf-global-options.ts";

export const partial = true;
---

{registerOptions}
{registerFrontPage}

4. Use phpVars in your templates

import { phpVars, optionsPhpVars } from './fields.ts';

console.log(`<?php echo ${phpVars.hero_home.title}; ?>`);
console.log(`<?php echo ${optionsPhpVars.footer_note}; ?>`);