redirect_post

Redirect to previous page.

Description

redirect_post( (string) $post_id = '' ); 

Parameters (1)

0. $post_id — Optional. (string) => ''
Post ID.

Usage

  1. if ( !function_exists( 'redirect_post' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/post.php'; 
  3.  
  4. // Optional. Post ID. 
  5. $post_id = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = redirect_post($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/post.php  
  1. function redirect_post($post_id = '') { 
  2. if ( isset($_POST['save']) || isset($_POST['publish']) ) { 
  3. $status = get_post_status( $post_id ); 
  4.  
  5. if ( isset( $_POST['publish'] ) ) { 
  6. switch ( $status ) { 
  7. case 'pending': 
  8. $message = 8; 
  9. break; 
  10. case 'future': 
  11. $message = 9; 
  12. break; 
  13. default: 
  14. $message = 6; 
  15. } else { 
  16. $message = 'draft' == $status ? 10 : 1; 
  17.  
  18. $location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) ); 
  19. } elseif ( isset($_POST['addmeta']) && $_POST['addmeta'] ) { 
  20. $location = add_query_arg( 'message', 2, wp_get_referer() ); 
  21. $location = explode('#', $location); 
  22. $location = $location[0] . '#postcustom'; 
  23. } elseif ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) { 
  24. $location = add_query_arg( 'message', 3, wp_get_referer() ); 
  25. $location = explode('#', $location); 
  26. $location = $location[0] . '#postcustom'; 
  27. } else { 
  28. $location = add_query_arg( 'message', 4, get_edit_post_link( $post_id, 'url' ) ); 
  29.  
  30. /** 
  31. * Filters the post redirect destination URL. 
  32. * @since 2.9.0 
  33. * @param string $location The destination URL. 
  34. * @param int $post_id The post ID. 
  35. */ 
  36. wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) ); 
  37. exit;