函数文档

get_available_post_statuses()

💡 云策文档标注

概述

get_available_post_statuses() 函数用于获取指定文章类型的所有可用状态。它通过 wp_count_posts() 函数计算状态并返回数组。

关键要点

  • 参数 $type 为字符串类型,指定文章类型,默认值为 'post'。
  • 返回值为字符串数组,包含指定文章类型的所有状态。
  • 内部实现基于 wp_count_posts() 函数,通过 array_keys() 提取状态键名。

代码示例

function get_available_post_statuses( $type = 'post' ) {
    $statuses = wp_count_posts( $type );
    return array_keys( get_object_vars( $statuses ) );
}

注意事项

  • 该函数自 WordPress 2.5.0 版本引入。
  • 相关函数包括 wp_count_posts() 用于计数,wp_edit_posts_query() 用于查询编辑页面文章。

📄 原文内容

Returns all the possible statuses for a post type.

Parameters

$typestringrequired
The post_type you want the statuses for. Default 'post'.

Return

string[] An array of all the statuses for the supplied post type.

Source

function get_available_post_statuses( $type = 'post' ) {
	$statuses = wp_count_posts( $type );

	return array_keys( get_object_vars( $statuses ) );
}

Changelog

Version Description
2.5.0 Introduced.