wp_add_trashed_suffix_to_post_name_for_trashed_posts

Adds a suffix if any trashed posts have a given slug.

Description

wp_add_trashed_suffix_to_post_name_for_trashed_posts( (string) $post_name, (int) $post_ID = 0 ); 

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

For internal use.

Parameters (2)

0. $post_name (string)
The post name.
1. $post_id — Optional. (int)
Post ID that should be ignored. Default 0.

Usage

  1. if ( !function_exists( 'wp_add_trashed_suffix_to_post_name_for_trashed_posts' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post name. 
  5. $post_name = ''; 
  6.  
  7. // Optional. Post ID that should be ignored. Default 0. 
  8. $post_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_add_trashed_suffix_to_post_name_for_trashed_posts($post_name, $post_id); 
  12.  

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_trashed_posts( $post_name, $post_ID = 0 ) { 
  2. $trashed_posts_with_desired_slug = get_posts( array( 
  3. 'name' => $post_name,  
  4. 'post_status' => 'trash',  
  5. 'post_type' => 'any',  
  6. 'nopaging' => true,  
  7. 'post__not_in' => array( $post_ID ) 
  8. ) ); 
  9.  
  10. if ( ! empty( $trashed_posts_with_desired_slug ) ) { 
  11. foreach ( $trashed_posts_with_desired_slug as $_post ) {