I am creating a new post using the wp_insert_post function. Here's what that code looks like:

$new_post = array(
            'post_title' => $newtitle,
            'post_status' => 'publish',
            'post_content' => $repost[content],
            'post_excerpt' => $repost[excerpt],
            'post_author' => 1,
            'post_type' => 'post',
            'post_category' => explode(",",$catlist),


The post is created fine, but I'd like to fire some other functions, such as Jetpack's social posting tools (Publicize.) Is there code to do that or would I be better in changing the post_status to draft and setting a future publishing date?

2 Answers 2


Use this code snippet to use another function,

function my_function( $post_id ) {

    //Some code
add_action( 'save_post', 'my_function' );

This fires when a post is inserted.

  • Keep in mind this also fires when a post is updated. Apr 21, 2014 at 13:54
  • Yes @hereswhatidid.. This fires along with the existing functionality. Apr 21, 2014 at 13:55
  • 1
    Thanks - you can also hook into wp_insert_post I learned from this answer in another thread Post Apr 21, 2014 at 14:04
  • Yeah Great. If your problem is fixed, please update your answer and mark the question as resolved. So others will get help from this post :) Apr 21, 2014 at 14:07

wp_insert_post will trigger a number of hooks:

  • save_post_{$post->post_type}
  • save_post
  • wp_insert_post
  • the transition post hooks
  • possibly edit_post and post_updated
  • and certainly some others

So, yes, there are a number of ways to trigger other functions. Use add_action or add_filter to apply a callback to the hook appropriate for your purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.