Skip to content

React When a Field Group Definition Changes

Table of Contents

Two actions fire when a definition is saved or changed. They are the hook to use for deploy automation, cache purging, or keeping something else in step with your data model.

What It Does

nxt/definition_saved fires when a definition is written, with the post ID, its kind and its meta. nxt/definition_changed is the broader signal that something in the model moved.

Before You Start

  • Nexter Extension 4.9.0 or later with Content Fields enabled.
  • Somewhere to add PHP — a child theme, a small plugin, or a Nexter code snippet.
  • You know the key you want to affect.

Hook a Definition Change

  1. Add an action on nxt/definition_saved with three arguments, or nxt/definition_changed with two.
The Group Fields tab, whose definitions these actions fire for
  1. Check the $kind if you only care about one — group_fields, cpt or taxonomy.
  1. Do your work: purge a cache, write a log line, trigger a rebuild.
  1. Keep it fast. These fire during an admin save.

When to Use It

  • Purging a page cache or CDN when the data model changes.
  • Logging model changes for an audit trail.
  • Triggering a static rebuild on a headless site.

Display the Value

Purging a cache when a field group changes:

<?php
add_action( 'nxt/definition_saved', function ( $post_id, $kind, $meta ) {
    if ( 'group_fields' !== $kind ) {
        return;
    }
    // your own cache, a CDN purge, a rebuild trigger
    error_log( 'Field group saved: ' . ( $meta['key'] ?? '' ) );
}, 10, 3 );

add_action( 'nxt/definition_changed', function ( $post_id, $kind ) {
    // broader signal - fires for model changes generally
}, 10, 2 );

Limitations

  • These fire on definition changes, not on field values. Saving a post does not trigger them.
  • nxt/definition_changed can fire with a post ID of 0 when the change did not come from a single definition post. Do not assume a valid ID.
  • They run inside an admin request, so slow work here makes saving a field group feel slow. Queue anything heavy.

Troubleshooting

The action does not fire when I edit a post

Correct. These are for definition changes, not value changes. Use WordPress’ own save_post for values.

I get a post ID of 0

Expected for changes that are not tied to one definition post. Guard before using the ID.

Related Docs

Share your Thoughts

Still in Doubt? Let’s Assist You

Have Feedback or Questions?

Join our WordPress Community on Facebook!