wp_add_trashed_suffix_to_post_name_for_post

Adds a trashed suffix for a given post.

Description

(string) wp_add_trashed_suffix_to_post_name_for_post( (WP_Post) $post ); 

Store its desired (i.e. current) slug so it can try to reclaim it if the post is untrashed.

For internal use.

Returns (string)

New slug for the post.

Parameters (1)

0. $post (WP_Post)
The post.

Usage

  1. if ( !function_exists( 'wp_add_trashed_suffix_to_post_name_for_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_add_trashed_suffix_to_post_name_for_post($post); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function wp_add_trashed_suffix_to_post_name_for_post( $post ) { 
  2. global $wpdb; 
  3.  
  4. $post = get_post( $post ); 
  5.  
  6. if ( '__trashed' === substr( $post->post_name, -9 ) ) { 
  7. return $post->post_name; 
  8. add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name ); 
  9. $post_name = _truncate_post_slug( $post->post_name, 191 ) . '__trashed'; 
  10. $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); 
  11. clean_post_cache( $post->ID ); 
  12. return $post_name;