get_preview_post_link

函数
get_preview_post_link ( $post = null, $query_args = array(), $preview_link = '' )
参数
  • (int|WP_Post) $post Optional. Post ID or `WP_Post` object. Defaults to global `$post`.
    Required:
    Default: null
  • (array) $query_args Optional. Array of additional query args to be appended to the link. Default empty array.
    Required:
    Default: array()
  • (string) $preview_link Optional. Base preview link to be used if it should differ from the post permalink. Default empty.
    Required:
    Default: (empty)
返回值
  • (string|null) URL used for the post preview, or null if the post does not exist.
定义位置
相关方法
get_previous_post_linkget_previous_posts_linkget_edit_post_linkget_previous_posts_page_linkget_delete_post_link
引入
4.4.0
弃用
-

get_preview_post_link函数是一个WordPress函数,用于检索预览一个指定文章的URL: 这个函数以文章的ID为参数,返回预览指定文章的URL。

检索用于文章预览的URL。

允许添加额外的查询参数。

function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return;
	}

	$post_type_object = get_post_type_object( $post->post_type );
	if ( is_post_type_viewable( $post_type_object ) ) {
		if ( ! $preview_link ) {
			$preview_link = set_url_scheme( get_permalink( $post ) );
		}

		$query_args['preview'] = 'true';
		$preview_link          = add_query_arg( $query_args, $preview_link );
	}

	/**
	 * Filters the URL used for a post preview.
	 *
	 * @since 2.0.5
	 * @since 4.0.0 Added the `$post` parameter.
	 *
	 * @param string  $preview_link URL used for the post preview.
	 * @param WP_Post $post         Post object.
	 */
	return apply_filters( 'preview_post_link', $preview_link, $post );
}

常见问题

FAQs
查看更多 >