函数文档

wp_get_single_post()

💡 云策文档标注

概述

wp_get_single_post() 是一个已弃用的 WordPress 函数,用于根据文章 ID 检索单篇文章数据。自 WordPress 3.5.0 起,建议使用 get_post() 替代。

关键要点

  • 函数已弃用:自 WordPress 3.5.0 起,wp_get_single_post() 被标记为弃用,应改用 get_post()。
  • 参数说明:接受两个参数:$postid(必需,文章 ID)和 $mode(可选,返回结果模式,如 OBJECT、ARRAY_N 或 ARRAY_A)。
  • 返回类型:返回 WP_Post 对象或数组,包含文章内容和信息,若无匹配则返回 null。
  • 内部实现:函数内部调用 _deprecated_function() 并转发到 get_post()。

代码示例

function wp_get_single_post( $postid = 0, $mode = OBJECT ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'get_post()' );
    return get_post( $postid, $mode );
}

注意事项

  • 兼容性:在开发新代码时,应避免使用此函数,以保持与最新 WordPress 版本的兼容性。
  • 替代函数:使用 get_post() 作为标准方法来检索文章数据。

📄 原文内容

Retrieve a single post, based on post ID.

Description

Has categories in ‘post_category’ property or key. Has tags in ‘tags_input’ property or key.

See also

Parameters

$postidintrequired
Post ID.
$modestringoptional
How to return result, either OBJECT, ARRAY_N, or ARRAY_A.

Default:OBJECT

Return

WP_Post|null Post object or array holding post contents and information

Source

function wp_get_single_post( $postid = 0, $mode = OBJECT ) {
	_deprecated_function( __FUNCTION__, '3.5.0', 'get_post()' );
	return get_post( $postid, $mode );
}

Changelog

Version Description
3.5.0 Deprecated. Use get_post()
1.0.0 Introduced.