_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
See also
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
Return
(string) Post states string.
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.3.0 | Added the $display parameter and a return value. |
2.7.0 | Introduced. |