Title: wp_publish_post
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_publish_post( int|WP_Post $post )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#wp--skip-link--target)

Publishes a post by transitioning the post status.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
required

Post ID or post object.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#more-information)󠁿

This function does not do anything except transition the post status. If you want
to ensure post_name is set, use [wp_update_post()](https://developer.wordpress.org/reference/functions/wp_update_post/)
instead.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#source)󠁿

    ```php
    function wp_publish_post( $post ) {
    	global $wpdb;

    	$post = get_post( $post );

    	if ( ! $post ) {
    		return;
    	}

    	if ( 'publish' === $post->post_status ) {
    		return;
    	}

    	$post_before = get_post( $post->ID );

    	// Ensure at least one term is applied for taxonomies with a default term.
    	foreach ( get_object_taxonomies( $post->post_type, 'object' ) as $taxonomy => $tax_object ) {
    		// Skip taxonomy if no default term is set.
    		if (
    			'category' !== $taxonomy &&
    			empty( $tax_object->default_term )
    		) {
    			continue;
    		}

    		// Do not modify previously set terms.
    		if ( ! empty( get_the_terms( $post, $taxonomy ) ) ) {
    			continue;
    		}

    		if ( 'category' === $taxonomy ) {
    			$default_term_id = (int) get_option( 'default_category', 0 );
    		} else {
    			$default_term_id = (int) get_option( 'default_term_' . $taxonomy, 0 );
    		}

    		if ( ! $default_term_id ) {
    			continue;
    		}
    		wp_set_post_terms( $post->ID, array( $default_term_id ), $taxonomy );
    	}

    	$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );

    	clean_post_cache( $post->ID );

    	$old_status        = $post->post_status;
    	$post->post_status = 'publish';
    	wp_transition_post_status( 'publish', $old_status, $post );

    	/** This action is documented in wp-includes/post.php */
    	do_action( "edit_post_{$post->post_type}", $post->ID, $post );

    	/** This action is documented in wp-includes/post.php */
    	do_action( 'edit_post', $post->ID, $post );

    	/** This action is documented in wp-includes/post.php */
    	do_action( "save_post_{$post->post_type}", $post->ID, $post, true );

    	/** This action is documented in wp-includes/post.php */
    	do_action( 'save_post', $post->ID, $post, true );

    	/** This action is documented in wp-includes/post.php */
    	do_action( 'wp_insert_post', $post->ID, $post, true );

    	wp_after_insert_post( $post, true, $post_before );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post.php#L5308)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post.php#L5308-L5374)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#hooks)󠁿

 [do_action( ‘edit_post’, int $post_id, WP_Post $post )](https://developer.wordpress.org/reference/hooks/edit_post/)

Fires once an existing post has been updated.

 [do_action( “edit_post_{$post->post_type}”, int $post_id, WP_Post $post )](https://developer.wordpress.org/reference/hooks/edit_post_post-post_type/)

Fires once an existing post has been updated.

 [do_action( ‘save_post’, int $post_id, WP_Post $post, bool $update )](https://developer.wordpress.org/reference/hooks/save_post/)

Fires once a post has been saved.

 [do_action( “save_post_{$post->post_type}”, int $post_id, WP_Post $post, bool $update )](https://developer.wordpress.org/reference/hooks/save_post_post-post_type/)

Fires once a post has been saved.

 [do_action( ‘wp_insert_post’, int $post_id, WP_Post $post, bool $update )](https://developer.wordpress.org/reference/hooks/wp_insert_post/)

Fires once a post has been saved.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_after_insert_post()](https://developer.wordpress.org/reference/functions/wp_after_insert_post/)`wp-includes/post.php` |

Fires actions after a post, its terms and meta data has been saved.

  | 
| [get_the_terms()](https://developer.wordpress.org/reference/functions/get_the_terms/)`wp-includes/category-template.php` |

Retrieves the terms of the taxonomy that are attached to the post.

  | 
| [get_object_taxonomies()](https://developer.wordpress.org/reference/functions/get_object_taxonomies/)`wp-includes/taxonomy.php` |

Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.

  | 
| [clean_post_cache()](https://developer.wordpress.org/reference/functions/clean_post_cache/)`wp-includes/post.php` |

Will clean the post in the cache.

  | 
| [wp_set_post_terms()](https://developer.wordpress.org/reference/functions/wp_set_post_terms/)`wp-includes/post.php` |

Sets the terms for a post.

  | 
| [wp_transition_post_status()](https://developer.wordpress.org/reference/functions/wp_transition_post_status/)`wp-includes/post.php` |

Fires actions related to the transitioning of a post’s status.

  | 
| [wpdb::update()](https://developer.wordpress.org/reference/classes/wpdb/update/)`wp-includes/class-wpdb.php` |

Updates a row in the table.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#)

| Used by | Description | 
| [check_and_publish_future_post()](https://developer.wordpress.org/reference/functions/check_and_publish_future_post/)`wp-includes/post.php` |

Publishes future post and make sure post ID has future post status.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_publish_post/?output_format=md#comment-content-5866)
 2.   [Pratham](https://profiles.wordpress.org/pratham2003/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/wp_publish_post/#comment-5866)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_publish_post%2F%23comment-5866)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_publish_post%2F%23comment-5866)
 4. Feedback: The function name does not seem to indicate that it does not do the usual
    actions expected from transitioning a post to publish status. The note inside “
    more information” is easy to miss.
 5. Can the following note be moved from more information to the main description?
    `
    This function does not do anything except transition the post status. If you want
    to ensure post_name is set, use wp_update_post() instead.`
 6. P.S. Just a thought (I don’t have the full context), if the function is only supposed
    to be used when publishing a future post then consider deprecating this and creating
    a new one called `wp_publish_future_post`?
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_publish_post%2F%3Freplytocom%3D5866%23feedback-editor-5866)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_publish_post%2F)
before being able to contribute a note or feedback.