wp_unique_post_slug example

$post->post_name   = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
    }

    /* * If the user wants to set a new name -- override the current one. * Note: if empty name is supplied -- use the title instead, see #6072. */
    if ( ! is_null( $name ) ) {
        $post->post_name = sanitize_title( $name ? $name : $title$post->ID );
    }

    $post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );

    $post->filter = 'sample';

    $permalink = get_permalink( $post, true );

    // Replace custom post_type token with generic pagename token for ease of use.     $permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );

    // Handle page hierarchy.     if ( $ptype->hierarchical ) {
        $uri = get_page_uri( $post );
        
$prepared_post->post_type = $this->post_type;

        if ( ! empty( $prepared_post->post_name )
            && ! empty( $prepared_post->post_status )
            && in_array( $prepared_post->post_status, array( 'draft', 'pending' ), true )
        ) {
            /* * `wp_unique_post_slug()` returns the same slug for 'draft' or 'pending' posts. * * To ensure that a unique slug is generated, pass the post data with the 'publish' status. */
            $prepared_post->post_name = wp_unique_post_slug(
                $prepared_post->post_name,
                $prepared_post->id,
                'publish',
                $prepared_post->post_type,
                $prepared_post->post_parent
            );
        }

        $post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true, false );

        if ( is_wp_error( $post_id ) ) {

            
$tax_object = get_taxonomy( $taxonomy );
            /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
            if ( ! apply_filters( 'quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy$post['post_type'] ) ) {
                unset( $data['tax_input'][ $taxonomy ] );
            }
        }
    }

    // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.     if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ), true ) ) {
        $post['post_status'] = 'publish';
        $data['post_name']   = wp_unique_post_slug( $data['post_name']$post['ID']$post['post_status']$post['post_type']$post['post_parent'] );
    }

    // Update the post.     edit_post();

    $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );

    $mode = 'excerpt' === $_POST['post_view'] ? 'excerpt' : 'list';

    $level = 0;
    if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) {
        
if ( $add_trashed_suffix ) {
            wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name$post_id );
        }
    }

    // When trashing an existing post, change its slug to allow non-trashed posts to use it.     if ( 'trash' === $post_status && 'trash' !== $previous_status && 'new' !== $previous_status ) {
        $post_name = wp_add_trashed_suffix_to_post_name_for_post( $post_id );
    }

    $post_name = wp_unique_post_slug( $post_name$post_id$post_status$post_type$post_parent );

    // Don't unslash.     $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : '';

    // Expected_slashed (everything!).     $data = compact(
        'post_author',
        'post_date',
        'post_date_gmt',
        'post_content',
        'post_content_filtered',
        
Home | Imprint | This part of the site doesn't use cookies.