do_action( 'save_post', int $post_ID, WP_Post $post, bool $update )

Fires once a post has been saved.

Description Description

Parameters Parameters


(int) Post ID.


(WP_Post) Post object.


(bool) Whether this is an existing post being updated or not.

Top ↑

Source Source

File: wp-includes/post.php

View on Trac

Top ↑

Changelog Changelog

Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Jason Adams

    When using WordPress 3.7 or later, it’s a good idea to use the save_post_{$post->post_type} hook when it makes sense to in order to reduce code and fire less hooks overall when posts are created and updated.

    Documentation can be found here:

  2. Skip to note 2 content
    Contributed by Aurovrata Venet

    Force a new post of have specific category term,

    add_action( 'save_post', 'set_post_default_category', 10,3 );
    function set_post_default_category( $post_id, $post, $update ) {
    	// Only want to set if this is a new post!
    	if ( $update ){
    	// Only set for post_type = post!
    	if ( 'post' !== $post->post_type ) {
    	// Get the default term using the slug, its more portable!
    	$term = get_term_by( 'slug', 'my-custom-term', 'category' );
    	wp_set_post_terms( $post_id, $term->term_id, 'category', true );

You must log in before being able to contribute a note or feedback.