get_blog_post()获取一个站点的文章(多站点)

目录

描述

Get a blog post from any site on the network. This function is the same as get_post(), except that it can retrieve a post from any site on the network, not just the current site.

get_blog_post() 描述

用法

 <?php get_blog_post$blog_id$post_id ); ?> 

get_blog_post() 用法

参数

$blog_id

(integer) (必填) ID of the blog.

默认值: None

$post_id

(integer) (必填) ID of the post you are looking for.

默认值: None

get_blog_post() 参数

历史

get_blog_post() 历史

源文件

get_blog_post() 函数的代码位于 wp-includes/ms-functions.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Get a blog post from any site on the network.
 *
 * @since MU 1.0
 *
 * @param int $blog_id ID of the blog.
 * @param int $post_id ID of the post you're looking for.
 * @return WP_Post|null WP_Post on success or null on failure
 */
function get_blog_post( $blog_id, $post_id ) {
	switch_to_blog( $blog_id );
	$post = get_post( $post_id );
	restore_current_blog();

	return $post;
}

get_blog_post() 源文件

相关