_post_states() WordPress Function

The post_states() function is used to display the current post state for a post. The post states are displayed in the post row actions area.

_post_states( WP_Post $post, bool $display = true ) #

Echoes or returns the post states as HTML.


Description

Top ↑

See also


Top ↑

Parameters

$post

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

$display

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

Default value: true


Top ↑

Return

(string) Post states string.


Top ↑

Source

File: wp-admin/includes/template.php

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;

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

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

	if ( $display ) {
		echo $post_states_string;
	}

	return $post_states_string;
}


Top ↑

Changelog

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

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.