get_sample_permalink( int $id, string $title = null, string $name = null )
Get a sample permalink based off of the post name.
描述
参数
- $id
-
(int)
(Required)
Post ID or post object. - $title
-
(string)
(Optional)
Title to override the post's current title when generating the post name.Default value: null
- $name
-
(string)
(Optional)
Name to override the post name.Default value: null
返回值
(array) Array containing the sample permalink with placeholder for the post name, and the post name.
源代码
File: wp-admin/includes/post.php
function get_sample_permalink($id, $title = null, $name = null) {
$post = get_post( $id );
if ( ! $post )
return array( '', '' );
$ptype = get_post_type_object($post->post_type);
$original_status = $post->post_status;
$original_date = $post->post_date;
$original_name = $post->post_name;
// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {
$post->post_status = 'publish';
$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
更新日志
Version | 描述 |
---|---|
2.5.0 | Introduced. |
相关函数
Uses
-
wp-admin/includes/post.php:
get_sample_permalink -
wp-admin/edit-tag-form.php:
editable_slug -
wp-includes/formatting.php:
untrailingslashit() -
wp-includes/formatting.php:
sanitize_title() -
wp-includes/link-template.php:
get_permalink() -
wp-includes/plugin.php:
apply_filters() -
wp-includes/post.php:
get_page_uri() -
wp-includes/post.php:
wp_unique_post_slug() -
wp-includes/post.php:
get_post() -
wp-includes/post.php:
get_post_type_object()
Show 5 more uses
Used By
-
wp-admin/includes/post.php:
get_sample_permalink_html()
你可能对这些文章感兴趣:
- wordpress函数get_the_posts_navigation()用法示例
- wordpress函数get_the_title()用法示例
- wordpress函数get_the_terms()用法示例
- wordpress函数get_the_tags()用法示例
- wordpress函数get_the_taxonomies()用法示例
- wordpress函数get_the_posts_pagination()用法示例
- wordpress函数get_the_permalink()用法示例
- wordpress函数get_the_password_form()用法示例
- wordpress函数get_the_modified_date()用法示例
- wordpress函数get_the_modified_time()用法示例
- wordpress函数get_the_modified_author()用法示例
- wordpress函数get_the_guid()用法示例
- wordpress函数get_the_ID()用法示例
- wordpress函数get_the_excerpt()用法示例
如有疑问,请前往问答中心反馈!
反馈