_post_states( WP_Post $post, bool $echo = true )

Function to echo or return the post states as HTML.

Description

See also

Parameters

$post

(WP_Post) (Required) The post to retrieve states for.

$echo

(bool) (Optional) Whether to echo the post states as an HTML string.

Default value: true

Return

(string) Post states string.

Source

File: wp-admin/includes/template.php

function _post_states( $post, $echo = true ) {
	$post_states        = get_post_states( $post );
	$post_states_string = '';

	if ( ! empty( $post_states ) ) {
		$state_count = count( $post_states );
		$i           = 0;

		$post_states_string .= ' — ';

		foreach ( $post_states as $state ) {
			$sep = ( ++$i === $state_count ) ? '' : ', ';

			$post_states_string .= "<span class='post-state'>$state$sep</span>";
		}
	}

	if ( $echo ) {
		echo $post_states_string;
	}

	return $post_states_string;
}

Changelog

Version Description
5.3.0 Added the $echo parameter and a return value.
2.7.0 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_post_states