get_post_stati()WP 3.0.0

Get a list of post statuses.

No Hooks.

Return

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

Usage

get_post_stati( $args, $output, $operator );
$args(array|string)
Array or string of post status arguments to compare against properties of the global $wp_post_statuses objects.
Default: empty array
$output(string)
The type of output to return, either 'names' or 'objects'.
Default: 'names'
$operator(string)
The logical operation to perform. 'or' means only one element from the array needs to match; 'and' means all elements must match.
Default: 'and'

Examples

0

#1 Get the names of all kinds of statuses on the blog: [auto-translate]

$stati = get_post_stati();

/* $stati = 
Array (
	[publish]    => publish
	[future]     => future
	[draft]      => draft
	[pending]    => pending
	[private]    => private
	[trash]      => trash
	[auto-draft] => auto-draft
	[inherit]    => inherit
)
*/
0

#2 Get objects of all kinds of statuses on the blog: [auto-translate]

$stati = get_post_stati( 0, 'a' );

$stati will contain:

Array
(
	[publish] => stdClass Object
		(
			[label] => Published
			[label_count] => Array
				(
					[0] => Published (%s)
					[1] => Published (%s)
					[singular] => Published (%s)
					[plural] => Published (%s)
					[context] => 
					[domain] => 
				)

			[exclude_from_search] => 
			[_builtin] => 1
			[public] => 1
			[internal] => 
			[protected] => 
			[private] => 
			[publicly_queryable] => 1
			[show_in_admin_status_list] => 1
			[show_in_admin_all_list] => 1
			[name] => publish
		)

	[future] => stdClass Object
		(
			[label] => Scheduled
			[label_count] => Array
				(
					[0] => Scheduled (%s)
					[1] => Scheduled (%s)
					[singular] => Scheduled (%s)
					[plural] => Scheduled (%s)
					[context] => 
					[domain] => 
				)

			[exclude_from_search] => 
			[_builtin] => 1
			[public] => 
			[internal] => 
			[protected] => 1
			[private] => 
			[publicly_queryable] => 
			[show_in_admin_status_list] => 1
			[show_in_admin_all_list] => 1
			[name] => future
		)

	[draft] => stdClass Object
		(
			[label] => Draft
			[label_count] => Array
				(
					[0] => Draft (%s)
					[1] => Drafts (%s)
					[singular] => Draft (%s)
					[plural] => Drafts (%s)
					[context] => 
					[domain] => 
				)

			[exclude_from_search] => 
			[_builtin] => 1
			[public] => 
			[internal] => 
			[protected] => 1
			[private] => 
			[publicly_queryable] => 
			[show_in_admin_status_list] => 1
			[show_in_admin_all_list] => 1
			[name] => draft
		)

	[pending] => stdClass Object
		(
			[label] => Pending
			[label_count] => Array
				(
					[0] => Pending (%s)
					[1] => Pending (%s)
					[singular] => Pending (%s)
					[plural] => Pending (%s)
					[context] => 
					[domain] => 
				)

			[exclude_from_search] => 
			[_builtin] => 1
			[public] => 
			[internal] => 
			[protected] => 1
			[private] => 
			[publicly_queryable] => 
			[show_in_admin_status_list] => 1
			[show_in_admin_all_list] => 1
			[name] => pending
		)

	[private] => stdClass Object
		(
			[label] => Private
			[label_count] => Array
				(
					[0] => Private (%s)
					[1] => Private (%s)
					[singular] => Private (%s)
					[plural] => Private (%s)
					[context] => 
					[domain] => 
				)

			[exclude_from_search] => 
			[_builtin] => 1
			[public] => 
			[internal] => 
			[protected] => 
			[private] => 1
			[publicly_queryable] => 
			[show_in_admin_status_list] => 1
			[show_in_admin_all_list] => 1
			[name] => private
		)

	[trash] => stdClass Object
		(
			[label] => Trash
			[label_count] => Array
				(
					[0] => Trash (%s)
					[1] => Trash (%s)
					[singular] => Trash (%s)
					[plural] => Trash (%s)
					[context] => 
					[domain] => 
				)

			[exclude_from_search] => 1
			[_builtin] => 1
			[public] => 
			[internal] => 1
			[protected] => 
			[private] => 
			[publicly_queryable] => 
			[show_in_admin_status_list] => 1
			[show_in_admin_all_list] => 
			[name] => trash
		)

	[auto-draft] => stdClass Object
		(
			[label] => auto-draft
			[label_count] => Array
				(
					[0] => auto-draft
					[1] => auto-draft
				)

			[exclude_from_search] => 1
			[_builtin] => 1
			[public] => 
			[internal] => 1
			[protected] => 
			[private] => 
			[publicly_queryable] => 
			[show_in_admin_status_list] => 
			[show_in_admin_all_list] => 
			[name] => auto-draft
		)

	[inherit] => stdClass Object
		(
			[label] => inherit
			[label_count] => Array
				(
					[0] => inherit
					[1] => inherit
				)

			[exclude_from_search] => 
			[_builtin] => 1
			[public] => 
			[internal] => 1
			[protected] => 
			[private] => 
			[publicly_queryable] => 
			[show_in_admin_status_list] => 
			[show_in_admin_all_list] => 
			[name] => inherit
		)

)
0

#3 Get the statuses with the desired parameters (status filter) [auto-translate]

In this example, we get the names of the statuses that have the publicly_queryable parameter set, i.e. the statuses that participate in the site search:

$stati = get_post_stati( [ 'publicly_queryable'=>true ], 'names' );

/* $stati =
Array(
	[publish] => publish
)
*/
0

#4 An example showing how the parameter $operator works [auto-translate]

Let's specify 2 parameters to the array $args. or - will output the statuses that have either the first or the second, and will output the statuses that have both parameters:

$stati = get_post_stati( 
	[ 'show_in_admin_status_list'=>true, 'protected'=>true ],
	'names',
	'or'
);

/* $stati =
Array (
	[publish] => publish
	[future]  => future
	[draft]   => draft
	[pending] => pending
	[private] => private
	[trash]   => trash
)
*/

and the same with "and":

$stati = get_post_stati( 
	[ 'show_in_admin_status_list'=>true, 'protected'=>true ],
	'names',
	'and'
);

/* $stati = 
Array (
	[future]  => future
	[draft]   => draft
	[pending] => pending
)
*/

Notes

Changelog

Since 3.0.0 Introduced.

Code of get_post_stati() WP 5.9.3

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 );
}