_post_states()WP 2.7.0

Echoes or returns the post states as HTML.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Return

String. Post states string.

Usage

_post_states( $post, $display );
$post(WP_Post) (required)
The post to retrieve states for.
$display(true|false)
Whether to display the post states as an HTML string.
Default: true

Notes

Changelog

Since 2.7.0 Introduced.
Since 5.3.0 Added the $display parameter and a return value.

_post_states() code WP 6.4.3

function _post_states( $post, $display = 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 ) {
			++$i;

			$separator = ( $i < $state_count ) ? ', ' : '';

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

	if ( $display ) {
		echo $post_states_string;
	}

	return $post_states_string;
}