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

Function to echo or return the post states as HTML.


Description Description

See also See also


Top ↑

Parameters 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


Top ↑

Return Return

(string) Post states string.



Top ↑

Source 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 ) {
			++$i;
			( $i == $state_count ) ? $sep = '' : $sep = ', ';
			$post_states_string          .= "<span class='post-state'>$state$sep</span>";
		}
	}

	if ( $echo ) {
		echo $post_states_string;
	}

	return $post_states_string;
}

Top ↑

Changelog Changelog

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

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.