wp_set_unique_slug_on_create_template_part
函数
wp_set_unique_slug_on_create_template_part ( $post_id )
- 参数
-
-
(int)
$post_id
Post ID.- Required: 是
-
(int)
- 定义位置
-
-
wp-includes/theme-templates.php
, line 13
-
wp-includes/theme-templates.php
- 引入
- 5.9.0
- 弃用
- –
Sets a custom slug when creating auto-draft template parts.
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.
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, wp_get_theme()->get_stylesheet(), 'wp_theme' ); } }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。