Title: _post_states
Published: April 25, 2014
Last modified: May 20, 2026

---

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

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#wp--skip-link--target)

Echoes or returns the post states as HTML.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#see-also)󠁿

 * [get_post_states()](https://developer.wordpress.org/reference/functions/get_post_states/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#parameters)󠁿

 `$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)required

The post to retrieve states for.

`$display`booloptional

Whether to display the post states as an HTML string.

Default:`true`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#return)󠁿

 string Post states string.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#source)󠁿

    ```php
    function _post_states( $post, $display = true ) {
    	$post_states      = get_post_states( $post );
    	$post_states_html = '';

    	if ( ! empty( $post_states ) ) {
    		$state_count = count( $post_states );
    		$separator   = wp_get_list_item_separator();

    		$i = 0;

    		$post_states_html .= ' &mdash; ';

    		foreach ( $post_states as $state ) {
    			++$i;

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

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

    	/**
    	 * Filters the HTML string of post states.
    	 *
    	 * @since 6.9.0
    	 *
    	 * @param string                 $post_states_html All relevant post states combined into an HTML string for display.
    	 *                                                 E.g. `&mdash; <span class='post-state'>Draft, </span><span class='post-state'>Sticky</span>`.
    	 * @param array<string, string>  $post_states      A mapping of post state slugs to translated post state labels.
    	 *                                                 E.g. `array( 'draft' => __( 'Draft' ), 'sticky' => __( 'Sticky' ), ... )`.
    	 * @param WP_Post                $post             The current post object.
    	 */
    	$post_states_html = apply_filters( 'post_states_html', $post_states_html, $post_states, $post );

    	if ( $display ) {
    		echo $post_states_html;
    	}

    	return $post_states_html;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/template.php#L2254)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/template.php#L2254-L2293)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#hooks)󠁿

 [apply_filters( ‘post_states_html’, string $post_states_html, array<string, , WP_Post $post )](https://developer.wordpress.org/reference/hooks/post_states_html/)

Filters the HTML string of post states.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_list_item_separator()](https://developer.wordpress.org/reference/functions/wp_get_list_item_separator/)`wp-includes/l10n.php` |

Retrieves the list item separator based on the locale.

  | 
| [get_post_states()](https://developer.wordpress.org/reference/functions/get_post_states/)`wp-admin/includes/template.php` |

Retrieves an array of post states from a post.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#)

| Used by | Description | 
| [WP_Posts_List_Table::column_title()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/column_title/)`wp-admin/includes/class-wp-posts-list-table.php` |

Handles the title column output.

  | 
| [Walker_Nav_Menu_Checklist::start_el()](https://developer.wordpress.org/reference/classes/walker_nav_menu_checklist/start_el/)`wp-admin/includes/class-walker-nav-menu-checklist.php` |

Start the element output.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_post_states/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Added the `$display` parameter and a return value. | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_post_states%2F)
before being able to contribute a note or feedback.