Site icon Hip-Hop Website Design and Development

Save current post using custom save button

I want to display a custom button in my “Edit post” screen which saves the current post (everything including custom fields) and then runs a function (in my case redirecting to another page).

I know how to redirect after saving the post using the save_posts action and wp_redirect but I can’t figure out how to save the post when a custom button is clicked.

This is my function for redirecting using save_post (which doesn’t work for me since I need to use a custom button):

function redirect_after_save_post() {
  global $post;

  if ( 'event' == get_post_type() ) {
    $url = 'http://www.google.com';
    wp_redirect( $url );
    exit;
  }
}

add_action( 'save_post', 'redirect_after_save_post' );