函数文档

get_post_stati()

💡 云策文档标注

概述

get_post_stati() 函数用于获取文章状态列表,支持通过参数过滤和指定输出格式。它基于全局 $wp_post_statuses 对象,并利用 wp_filter_object_list() 进行筛选。

关键要点

  • 函数返回文章状态名称或对象数组,默认输出为名称列表。
  • 参数 $args 可传入数组或字符串,用于匹配 $wp_post_statuses 的属性。
  • 参数 $output 控制输出类型,可选 'names' 或 'objects'。
  • 参数 $operator 指定逻辑操作,'or' 表示任一匹配,'and' 表示全部匹配。
  • 内部调用 wp_filter_object_list() 实现过滤功能。

代码示例

function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {
	global $wp_post_statuses;

	$field = ( 'names' === $output ) ? 'name' : false;

	return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field );
}

📄 原文内容

Gets a list of post statuses.

Description

See also

Parameters

$argsarray|stringoptional
Array or string of post status arguments to compare against properties of the global $wp_post_statuses objects.

Default:array()

$outputstringoptional
The type of output to return, either 'names' or 'objects'. Default 'names'.
$operatorstringoptional
The logical operation to perform. 'or' means only one element from the array needs to match; 'and' means all elements must match.
Default 'and'.

Return

string[]|stdClass[] A list of post status names or objects.

Source

function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {
	global $wp_post_statuses;

	$field = ( 'names' === $output ) ? 'name' : false;

	return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field );
}

Changelog

Version Description
3.0.0 Introduced.