get_post_permalink
函数
get_post_permalink ( $post = 0, $leavename = false, $sample = false )
- 参数
-
-
(int|WP_Post)
$post
Optional. Post ID or post object. Default is the global `$post`.- Required: 否
-
(bool)
$leavename
Optional. Whether to keep post name. Default false.- Required: 否
- Default: false
-
(bool)
$sample
Optional. Is it a sample permalink. Default false.- Required: 否
- Default: false
-
(int|WP_Post)
- 返回值
-
- (string|false) The post permalink URL. False if the post does not exist.
- 定义位置
-
-
wp-includes/link-template.php
, line 320
-
wp-includes/link-template.php
- 引入
- 3.0.0
- 弃用
- –
Retrieves the permalink for a post of a custom post type.
function get_post_permalink( $post = 0, $leavename = false, $sample = false ) { global $wp_rewrite; $post = get_post( $post ); if ( ! $post ) { return false; } $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); $slug = $post->post_name; $force_plain_link = wp_force_plain_post_permalink( $post ); $post_type = get_post_type_object( $post->post_type ); if ( $post_type->hierarchical ) { $slug = get_page_uri( $post ); } if ( ! empty( $post_link ) && ( ! $force_plain_link || $sample ) ) { if ( ! $leavename ) { $post_link = str_replace( "%$post->post_type%", $slug, $post_link ); } $post_link = home_url( user_trailingslashit( $post_link ) ); } else { if ( $post_type->query_var && ( isset( $post->post_status ) && ! $force_plain_link ) ) { $post_link = add_query_arg( $post_type->query_var, $slug, '' ); } else { $post_link = add_query_arg( array( 'post_type' => $post->post_type, 'p' => $post->ID, ), '' ); } $post_link = home_url( $post_link ); } /** * Filters the permalink for a post of a custom post type. * * @since 3.0.0 * * @param string $post_link The post's permalink. * @param WP_Post $post The post in question. * @param bool $leavename Whether to keep the post name. * @param bool $sample Is it a sample permalink. */ return apply_filters( 'post_type_link', $post_link, $post, $leavename, $sample ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。