Computes a unique slug for the post, when given the desired slug and some post details.
Signature
wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent )
- slug
- (string) the desired slug (post_name)
- post_ID
- (integer)
- post_status
- (string) no uniqueness checks are made if the post is still draft or pending
- post_type
- (string)
- post_parent
- (integer)
Return
(string) unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
Source
WP Trac GitHub Bitbucketfunction wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) return $slug; global $wpdb, $wp_rewrite; $original_slug = $slug; $feeds = $wp_rewrite->feeds; if ( ! is_array( $feeds ) ) $feeds = array(); $hierarchical_post_types = get_post_types( array('hierarchical' => true) ); if ( 'attachment' == $post_type ) { // Attachment slugs must be unique across all types. $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) ); if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { $suffix = 2;42 more lines...
Link here
-
URL
http://queryposts.com/function/wp_unique_post_slug/ -
HTML
<a href='http://queryposts.com/function/wp_unique_post_slug/'>wp_unique_post_slug()</a> -
Markdown
[wp_unique_post_slug()](http://queryposts.com/function/wp_unique_post_slug/) -
BBCode
[url=http://queryposts.com/function/wp_unique_post_slug/]wp_unique_post_slug()[/url]