wp_set_unique_slug_on_create_template_part()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_set_unique_slug_on_create_template_part( int $post_id )
Описание
Это нужно только для авточерновиков, создаваемых обычным редактором WP.
Если эта страница будет удалена, необходимость в этом отпадёт.
Оригинал (английский)
This is only needed for auto-drafts created by the regular WP editor.
If this page is to be removed, this will not be necessary.
Параметры
$post_id
int
обязательный
Исходный код
wp-includes/theme-templates.php:13
function wp_set_unique_slug_on_create_template_part( $post_id ) {
$post = get_post( $post_id );
if ( 'auto-draft' !== $post->post_status ) {
return;
}
if ( ! $post->post_name ) {
wp_update_post(
array(
'ID' => $post_id,
'post_name' => 'custom_slug_' . uniqid(),
)
);
}
$terms = get_the_terms( $post_id, 'wp_theme' );
if ( ! is_array( $terms ) || ! count( $terms ) ) {
wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
}
}
История изменений
| Версия | Описание |
|---|---|
| 5.9.0 | Introduced. |

