Using WordPress ‘get_post_stati()’ PHP function

The get_post_stati() WordPress PHP function retrieves a list of post statuses.

Usage

get_post_stati($args = array(), $output = 'names', $operator = 'and')

Parameters

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

More information

See WordPress Developer Resources: get_post_stati()

Examples

Get all post statuses

Get a list of all registered post statuses.

$post_statuses = get_post_stati();
print_r($post_statuses);

Get all public post statuses

Retrieve only public post statuses.

$args = array('public' => true);
$public_statuses = get_post_stati($args);
print_r($public_statuses);

Get post statuses as objects

Get the post statuses as objects instead of names.

$post_statuses = get_post_stati(array(), 'objects');
print_r($post_statuses);

Get post statuses with ‘OR’ operator

Find post statuses that are either public or private.

$args = array('public' => true, 'private' => true);
$public_private_statuses = get_post_stati($args, 'names', 'or');
print_r($public_private_statuses);

Get post statuses with custom properties

Retrieve post statuses with a custom property value.

$args = array('custom_property' => 'custom_value');
$custom_statuses = get_post_stati($args);
print_r($custom_statuses);