wp_add_trashed_suffix_to_post_name_for_trashed_posts()
Adds a suffix if any trashed posts have a given slug.
Store its desired (i.e. current) slug so it can try to reclaim it if the post is untrashed.
For internal use.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
null. Nothing (null).
Usage
wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_id );
- $post_name(string) (required)
- Post slug.
- $post_id(int)
- Post ID that should be ignored.
Changelog
| Since 4.5.0 | Introduced. |
wp_add_trashed_suffix_to_post_name_for_trashed_posts() wp add trashed suffix to post name for trashed posts code WP 6.9.1
function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_id = 0 ) {
$trashed_posts_with_desired_slug = get_posts(
array(
'name' => $post_name,
'post_status' => 'trash',
'post_type' => 'any',
'nopaging' => true,
'post__not_in' => array( $post_id ),
)
);
if ( ! empty( $trashed_posts_with_desired_slug ) ) {
foreach ( $trashed_posts_with_desired_slug as $_post ) {
wp_add_trashed_suffix_to_post_name_for_post( $_post );
}
}
}