WordPress Dynamic Hooks: The Complete save_post_{type} Guide
save_post_{type} fires before save_post, and meta and terms are not saved yet on REST saves. Tested hook order, guards, columns and loops on WordPress 7.1.4.

A dynamic hook is a hook whose name is built at run time from a variable. save_post_{$post_type} is the one most developers meet first: WordPress fires save_post_event for an event post, save_post_page for a page, and so on, so your callback only runs for the post type you care about. One fact that older guides get backwards: the type-specific hook fires before the general save_post hook, not after it. We confirmed that on 16 Nov 2026 in a disposable WordPress 7.1.4 install on PHP 8.3, and the core source says the same.
This guide covers what the hook fires on (and what it skips), how to save meta box data safely, why meta and terms can be empty on a block editor save, how to stop save loops, the admin column hooks people mix up, theme_mod_{$name}, the option filters, and how to find a dynamic hook name when a callback never runs. Every behaviour below comes from the core source or from a test we ran. Anything we could not test says so.
What is a dynamic hook, and does it work differently from a normal one?
No. WordPress has no special dispatch layer for dynamic hooks. When core runs do_action( "save_post_{$post->post_type}", ... ), PHP builds the string first (for example save_post_event), and WordPress looks that string up in the same $wp_filter registry it uses for every hook. Functions such as has_action() and remove_action() treat dynamic and fixed names identically.
The practical difference is only on the registering side. The name you pass to add_action() must match the built string exactly, including case and underscores, and nothing warns you when it does not match. A hook that never fires looks the same as a hook that fired with nothing attached. The Plugin Handbook chapter on hooks covers the basics of actions and filters if you want the background.
When does save_post_{$post_type} fire, and in what order?
It fires from wp_insert_post(), which wp_update_post() calls, and also from wp_publish_post(). Inside wp_insert_post() the order is fixed. We logged every hook for a test event post type and read the core source (wp-includes/post.php) to confirm:
edit_post_{$post_type}andedit_post, on updates only.post_updated, on updates only.save_post_{$post_type}, with$post_id,$postand$update.save_post, with the same three arguments.wp_insert_post, with the same three arguments.wp_after_insert_post, after the above, with$post_id,$post,$updateand$post_before.
The save_post_{$post_type} reference page says the hook has existed since WordPress 3.7.0, and one commenter there notes that it runs before save_post. That matches our log, where save_post_event always printed first. If you remove or override a callback that a plugin attached to save_post, remember the dynamic hook has already run by then.
What it does and does not fire on is where most surprises come from. This is what we saw:
What happened | save_post_event fired? | save_post fired? | Notes |
|---|---|---|---|
| Yes, | Yes | Also fires for the auto-draft created by “Add New” |
| Yes, | Yes | A revision is saved after the parent hooks |
Draft to published with | Yes, | Yes | Same path scheduled posts take when they go live |
Trash, then restore | Yes, both times | Yes | Status is |
| No | No | Meta writes never fire a save hook |
Permanent delete | No | No | Use |
Revision saved | No, | Yes, with post type | Why |
REST autosave of a published post | No | Yes, for the revision | Autosave is stored as a revision |
| No (nothing fired) | No | Attachments use |
Checked on 16 Nov 2026 with WordPress 7.1.4 and WP-CLI 2.12. The trash and restore rows surprise people: the hook fires on every status change that goes through wp_update_post(), so a callback that sends an email will send it on trash and on restore unless it checks $post->post_status.
If your goal is to react to a status change, a better hook may exist. WordPress also builds {$new_status}_{$post->post_type} and {$old_status}_to_{$new_status} inside transition_post_status(). In our test, publishing an event draft fired draft_to_publish and publish_event. Those fire only when the status actually changes, which is usually what a “send when published” feature needs.
How do I save meta box data safely on save_post_event?
Check four things before you write anything: it is not an autosave, it is not the auto-draft placeholder, the nonce is valid, and the current user may edit this post. The meta box below is the version we tested. It registers on add_meta_boxes_event, prints a nonce field, and saves one sanitised value.
// Checked on 16 Nov 2026, WordPress 7.1.4, PHP 8.3
add_action( 'add_meta_boxes_event', function ( $post ) {
add_meta_box( 'twp_event_details', 'Event details', 'twp_event_box', 'event', 'normal', 'default' );
} );
function twp_event_box( $post ) {
wp_nonce_field( 'twp_save_event', 'twp_event_nonce' );
$venue = get_post_meta( $post->ID, 'venue', true );
echo '<p><label for="twp_venue">Venue</label> ';
echo '<input type="text" id="twp_venue" name="twp_venue" value="' . esc_attr( $venue ) . '"></p>';
}
add_action( 'save_post_event', function ( $post_id, $post, $update ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( 'auto-draft' === $post->post_status ) {
return;
}
if ( ! isset( $_POST['twp_event_nonce'] )
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['twp_event_nonce'] ) ), 'twp_save_event' ) ) {
return;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
if ( isset( $_POST['twp_venue'] ) ) {
update_post_meta( $post_id, 'venue', sanitize_text_field( wp_unslash( $_POST['twp_venue'] ) ) );
}
}, 10, 3 );We drove that callback through wp_update_post() with a prepared $_POST to prove each guard can fail:
Request | Stored venue |
|---|---|
No nonce field | Nothing saved |
Nonce created for a different action | Nothing saved |
Valid nonce, but the current user is a guest | Nothing saved |
Valid nonce, administrator, input |
|
| Unchanged, value from the previous save kept |
Two details differ from most tutorials. First, on the dynamic hook you do not need a wp_is_post_revision() check. A revision is its own post type, so save_post_revision fires for it and save_post_event does not. On the general save_post hook the revision check is still needed, because we saw save_post fire for revisions. Second, a nonce is not a permission check. Keep current_user_can( 'edit_post', $post_id ) in place.
The autosave guard still matters on the dynamic hook. Core defines DOING_AUTOSAVE in both the classic autosave routine and the REST autosaves controller. Autosaves do not post your meta box fields, so without the guard a missing field can be treated as “empty” and overwrite a good value. See wp_is_post_autosave() if you want to test by post ID instead of the constant.
Why are my meta and terms empty inside save_post on a block editor save?
Because the block editor saves in several steps and save_post fires after the first one, before meta and terms are written. We posted a new event over the REST API with a registered meta value and read the meta inside save_post_event. It was an empty string. A few lines later, inside rest_after_insert_event, the same meta read back Main Hall. The REST controller calls wp_insert_post() first, then writes terms and registered meta, then fires rest_after_insert_{$post_type}, then wp_after_insert_post.
// Checked on 16 Nov 2026, WordPress 7.1.4
// Runs after the REST controller has saved terms and registered meta.
add_action( 'rest_after_insert_event', function ( $post, $request, $creating ) {
$venue = get_post_meta( $post->ID, 'venue', true ); // now populated
// ... react to the finished save here ...
}, 10, 3 );Use rest_after_insert_{$post_type} for REST saves, and wp_after_insert_post (WordPress 5.6 and later) when you want one hook that fires after core has finished saving through any path. See the reference pages for rest_after_insert_{$post_type} and wp_after_insert_post.
Two more things the block editor changes:
- Legacy meta boxes are saved in a second request. The block editor handbook says each active meta box area is submitted to
post.php?...&meta-box-loader=1, and that the loader mimics the normal form so normal hooks run. That meanssave_postcan fire twice for one click on Update: once for the REST save with no$_POST, once for the meta box submission with it. A Gutenberg issue still open on 16 Nov 2026 asks how to tell the two apart, and the answer in practice is your own nonce check, as in the example above. The nonce only exists in the second request. - Registered meta with a leading underscore can fail. We registered
_venuewithshow_in_restand posted it. The post was created, then the response was403, because a key that starts with an underscore counts as protected, and the REST meta update fails withrest_cannot_updateunless the registration includes anauth_callback. A second key registered with a callback saved fine. Use a key without the underscore, or add the callback in register_post_meta(). Also note the post type must supportcustom-fieldsfor REST meta to work.
Plugins that read data inside save_post for REST-driven editors hit this constantly. We cover how to debug the request side in our guide to debugging WordPress AJAX and REST requests.
Why does my save_post callback run in a loop?
Because the callback calls wp_update_post() or wp_insert_post(), which fires save_post_event again. WordPress has no guard against this. We attached a callback that called wp_update_post() on the same post and added a counter to stop it. It ran six times before the counter cut it off, and without the counter it would run until PHP gave up.
Pick the fix that suits the case:
- Write meta with
update_post_meta(). It fires no save hook (see the table above), so it cannot loop. This solves most cases. - Remove your own callback, update, add it back. We tested this pattern and the callback ran exactly once.
- Change the data before it is saved. The
wp_insert_post_datafilter lets you alter the post array without a second save.
// Checked on 16 Nov 2026, WordPress 7.1.4
add_action( 'save_post_event', 'twp_fix_title', 10, 1 );
function twp_fix_title( $post_id ) {
remove_action( 'save_post_event', 'twp_fix_title', 10 ); // stop the loop
wp_update_post( array( 'ID' => $post_id, 'post_title' => 'Event ' . $post_id ) );
add_action( 'save_post_event', 'twp_fix_title', 10, 1 );
}The test used a closure and a variable counter instead of a named function, which proves the pattern. A named function as shown is easier to remove and re-add, so prefer it.
Which admin column hooks fire for a post type, and why does manage_event_columns do nothing?
Because the screen ID for a post type list table is edit-event, not event and not event_posts. We opened edit.php?post_type=event with a logger on current_screen and on candidate filters. The screen ID was edit-event. These fired: manage_event_posts_columns, manage_edit-event_columns and manage_edit-event_sortable_columns, plus the action manage_event_posts_custom_column once per row. The name manage_event_columns, which some guides suggest, never fired.
The generic pattern in core is manage_{$screen->id}_columns, and it works because $screen->id is edit-event. Post types also get a friendlier alias, manage_{$post_type}_posts_columns. Either works for adding a column, and the alias is easier to read. The reference pages are manage_{$post_type}_posts_columns and manage_{$screen->id}_columns.
List table | Add a column | Fill the cell | Sortable list |
|---|---|---|---|
Post type |
|
|
|
Taxonomy |
|
|
|
Checked on 16 Nov 2026. The difference between the “fill the cell” columns matters: the post type hook is an action that echoes, the taxonomy hook is a filter that returns a string. In the core source, the terms table passes the column name through that filter only for columns it does not handle itself, so it only fires for your own custom columns. Mixing these up gives an empty cell and no error.
// Checked on 16 Nov 2026, WordPress 7.1.4. Adds a "Venue" column to the event list.
add_filter( 'manage_event_posts_columns', function ( $columns ) {
$columns['venue'] = 'Venue';
return $columns;
} );
add_action( 'manage_event_posts_custom_column', function ( $column, $post_id ) {
if ( 'venue' === $column ) {
echo esc_html( get_post_meta( $post_id, 'venue', true ) );
}
}, 10, 2 );On the test site the column header and the stored value (Main Hall) both rendered in the list. To log a screen ID you cannot guess, add add_action( 'current_screen', function ( $s ) { error_log( $s->id ); } ); temporarily and load the page. Our guide to why debug.log stays silent helps if nothing appears.
How does theme_mod_{$name} work, and what can it not do?
Every call to get_theme_mod( 'name' ) passes its value through apply_filters( "theme_mod_{$name}", ... ), so you can change one setting without touching the database. We tested three cases against a setting called twp_badge:
Situation | What get_theme_mod() returned |
|---|---|
Nothing saved, filter returns a fallback if the value is empty | The fallback. The filter also runs when the setting does not exist yet. |
Nothing saved, a default passed as the second argument | The default reaches your filter as its input |
Value saved, filter returns |
|
So the filter changes what code reads, and the stored value is untouched. It is a runtime override, not a way to lock a Customizer control. The preview and the control UI have their own state. The filter also runs wherever get_theme_mod() is called, including REST requests, AJAX and WP-CLI, so conditional tags such as is_singular() inside it can give wrong answers when no front-end query exists. Guard them with did_action( 'wp' ). See theme_mod_{$name} and get_theme_mod().
// Checked on 16 Nov 2026, WordPress 7.1.4
add_filter( 'theme_mod_twp_badge', function ( $value ) {
return $value ? $value : '#0b5fff'; // fallback when the setting is empty or missing
} );What do pre_option and option filters do, and why can they crash a site?
get_option() runs two dynamic filters. pre_option_{$option} runs first, before the database is read. If your callback returns anything other than false, WordPress uses it and skips the lookup. option_{$option} runs after the value is read and lets you change it. There are matching write-side hooks: pre_update_option_{$option}, sanitize_option_{$option} and update_option_{$option}.
We tested the first two. A pre_option_blogdescription callback returning PRE VALUE made get_option( 'blogdescription' ) return that string. A pre_option_blogname callback returning false fell through to the stored site title. An option_blogdescription callback received the stored value and its return replaced it.
The dangerous mistake is reading the same option inside its own pre_option_ callback. get_option() applies the filter again, which calls your callback again. We ran it with a 64 MB memory limit and PHP ended with “Allowed memory size of 67108864 bytes exhausted” in wp-includes/plugin.php, which WordPress reports as a critical error. If you need the real value, read a different option, or remove your filter before reading and add it back after. The reference pages are pre_option_{$option} and option_{$option}.
How do I build my own dynamic hooks?
Fire a general hook and a specific one, general first. Consumers choose how narrow to be. This function is the pattern we tested, and the table shows what each call produced.
// Checked on 16 Nov 2026, WordPress 7.1.4
function twp_get_config( $key, $context ) {
$value = 30;
$value = apply_filters( "twp_config_{$key}", $value, $context );
$value = apply_filters( "twp_config_{$key}_{$context}", $value );
return $value;
}
add_filter( 'twp_config_timeout', function ( $v ) { return $v + 5; } );
add_filter( 'twp_config_timeout_api_fetch', function ( $v ) { return $v * 2; } );Call | Result | Why |
|---|---|---|
| 70 | 30, plus 5 from the general filter, doubled by the specific one |
| 35 | Only the general filter matched |
A few rules keep your own hooks usable:
- Build names from a controlled set. Post type slugs, taxonomy slugs and your own context keys are fine. Raw user input is not. Validate it, or run it through
sanitize_key(), before it goes into a hook name. - Prefix every name with your plugin slug so it cannot collide with core or another plugin.
- Document the pattern in the docblock. A search for
twp_config_timeout_api_fetchfinds nothing in your source, because the string is never written out. The docs are the only discovery path. - Register post types in lowercase. We registered a post type called
Productand WordPress stored it asproduct(it appliessanitize_key()), so the hook wassave_post_product. Names are also limited to 20 characters, and longer ones fail with an error.
How do I find a dynamic hook name, and why does my callback never run?
Work through these checks in order. Each one narrows the problem from “hook name wrong” to “hook fired but my code did not run”.
- Is anything registered on that exact name?
wp eval 'var_dump( has_action( "save_post_event" ) );'printsbool(true)when something is attached andbool(false)when not. Run it with WP-CLI against the site, after plugins load. - Which callbacks and priorities are attached?
wp eval 'global $wp_filter; foreach ( $wp_filter["save_post_event"]->callbacks as $p => $cbs ) { echo $p, " => ", count( $cbs ), "\n"; }'. On our test site it listed priorities 10 and 20. - Did the hook fire at all? Attach a temporary callback to the
allhook and log names that start with your prefix, usingcurrent_filter(). We used this to capturetwp_config_timeoutandtwp_config_timeout_api_fetch. Theallhook runs for every hook, so use it briefly and never in production. - What is the real screen or post type slug? Log
$screen->idoncurrent_screenor runwp post-type list. - Is the hook registered late? A callback added after the hook already fired never runs. Register on
initor earlier for save hooks, and checkdid_action().
Two common debugging tips are wrong or incomplete. The WP-CLI flag --debug=hooks does not list WordPress hooks: it prints WP-CLI’s own internal command hooks, which we confirmed by running it. And wp hook list is not part of WP-CLI core. It comes from a separate package, wp-cli/hook-command, and returned “not a registered wp command” on a stock install.
Query Monitor helps, with one caveat. In version 4.1.1 its Hooks panel lists only actions that have fired on the request by default. Filters such as theme_mod_{$name} or the column filters appear only if you define QM_SHOW_ALL_HOOKS as true, which switches the panel to “Hooks, Actions, & Filters” and lists every registered hook. Our Query Monitor tutorial walks through the panels.
Which dynamic hooks in core are worth knowing?
We checked each name below in the WordPress 7.1.4 source on 16 Nov 2026.
Hook | Variable | Typical use |
|---|---|---|
| Post type slug | Save meta box data for one post type |
| Post type slug | React to updates only, not inserts |
| New status and type | React when a post type reaches a status, for example |
| Both statuses | React to one exact status change |
| Post type slug | Register meta boxes for one type |
| Post type slug | Run code after a REST save finishes |
| Post type slug | Change one type’s REST response |
| Post type slug | Add or remove list table columns |
| Post type slug | Print a custom column cell |
| Taxonomy slug | Add fields to the add-term form |
| Theme mod key | Override one Customizer value at read time |
| Option name | Short-circuit or change an option on read |
| Object type and key | Sanitise registered meta |
| Object type and key | Control who may edit protected meta |
| Screen ID | Add bulk actions to one list table |
| Admin page hook | Run code only on one admin page |
Two names that circulate in older guides are wrong. The meta read filter is get_{$meta_type}_metadata, not get_post_metadata_{$meta_type}. And sanitize_{$context}_{$field} is not a core hook name we could find; meta sanitising uses sanitize_{$object_type}_meta_{$meta_key}. The 12 filters that replace plugins article shows more real uses of filters like these.
What common mistakes do people report with save_post hooks?
We read the Gutenberg issue tracker and the WordPress developer reference on 16 Nov 2026. These problems recur, and each link goes to the original report.
- Meta and terms look old inside the hook. A Gutenberg issue opened in May 2019 (now closed) reported that
post_updatedandsave_postreturned terms from before the update in the block editor. That is the ordering we reproduced above. Read the data inrest_after_insert_{$post_type}instead. - The hook fires twice per save. A Gutenberg question from December 2018 (still open) describes one REST save and one meta box request, and asks for a way to skip the second. A separate report on transition_post_status (open since April 2019) describes the same status transition hooks firing twice.
- One editor save changes several posts. A 2021 issue, still open notes that saving several edited entities at once can trigger
save_posthooks in unexpected ways. Do not assume one save request equals one post. - Side effects on trash and restore. The developer reference page lists auto-drafts,
wp_update_post(), trash and restore among the triggers. Our table agrees. Check$post->post_statusbefore you send, charge or sync anything. - Updating the same post inside the hook. The reference page does not warn about loops. Use
update_post_meta()or the remove and re-add pattern shown above.
Issue states can change, so treat the open and closed labels as what we saw on 16 Nov 2026. We tested plain WordPress 7.1.4 and no page builder, so a builder or caching layer can add its own saves.
When should I not use a dynamic hook?
- When you need the same logic for every post type. Use
save_postand a type check, or a loop that registers the dynamic hook for each type in an array. - When the variable comes from outside your control. Dynamic names built from unchecked input are hard to predict and hard to remove. Use one fixed hook and pass the variable as an argument.
- When you really need a post-save event for any editor. Use
wp_after_insert_post, which fires after core has finished saving through every path. - When you only need to change data being saved. The
wp_insert_post_datafilter is simpler and loop-free. - When you would rather not maintain a hook per type. A scoped hook per type helps when the logic differs. If every callback ends up identical, one shared function attached to several names is clearer.
Scoped hooks also save work. A single save_post callback with a type check runs on every save for every type, including revisions. Scoped hooks run only where they apply. On most sites that cost is small, so choose by clarity first.
Questions people ask
Does save_post_{$post_type} run before or after save_post?
Before. In wp_insert_post() core fires save_post_{$post->post_type}, then save_post, then wp_insert_post. We logged the order on WordPress 7.1.4 and it matched the source.
Does save_post_{$post_type} fire for revisions and autosaves?
Not for revisions: a revision has the post type revision, so save_post_revision and the general save_post fire, and your type-specific hook does not. Autosaves of a published post are saved as revisions, so the same applies. Autosaves that update the post itself can still reach your hook with DOING_AUTOSAVE defined, so keep that check.
Why is $_POST empty in my save_post callback?
Because the save came from the REST API, WP-CLI or code that is not a form submission. Only the classic form and the block editor’s meta box request fill $_POST. Read from the post object or, on REST saves, from rest_after_insert_{$post_type}.
Why did my hook fire for an auto-draft?
Opening “Add New” creates an auto-draft through wp_insert_post(), which fires the save hooks. Return early when $post->post_status is auto-draft.
Can I hook save_post for several post types at once?
Yes. Loop over an array of slugs and call add_action( "save_post_{$type}", $callback, 10, 3 ) for each. The callback receives the post, so it can still branch on type if it must.
Are the screen ID and post type column hooks the same thing?
For a post type list table they do the same job through different names. The screen ID for post type event is edit-event, so the screen-based name is manage_edit-event_columns. Both fired in our test.
What PHP and WordPress versions did you test?
WordPress 7.1.4 on PHP 8.3 with Apache, MariaDB 11 and WP-CLI 2.12, on 16 Nov 2026. WordPress 7.1.4 is the current stable release at that date.
Plugins we build and run
We maintain these ourselves, which is why we can support them on your site.
- BuddyNextThe self-hosted community engine for WordPress
- BuddyXFree community theme, Pro when you outgrow it
- ReignPremium community theme. Add pieces, build anything
- JetonomyCommunity forum and Q&A for WordPress
- EventonomyEvents and RSVPs for WordPress communities
- LearnomyCourses and learning communities on WordPress
- ListoraDirectories and listings your members can browse
- SnipShareCode sharing built for developer communities
- WB Ad ManagerAd placements that turn traffic into revenue
- WP Career BoardA job board your community actually uses
- WP Sell ServicesSell services with offers, orders, and payouts
- MediaVersePhotos, video, and media albums for members
- WB GamificationPoints, badges, and rewards that keep members active
- Product RoadmapPublic roadmaps with voting your users trust



