apply_filters( ‘display_post_states’, string[] $post_states, WP_Post $post )

Filters the default post display states used in the posts list table.

Parameters

$post_statesstring[]
An array of post display states.
$postWP_Post
The current post object.

Source

return apply_filters( 'display_post_states', $post_states, $post );

Changelog

VersionDescription
5.5.0Also applied in the Customizer context. If any admin functions are used within the filter, their existence should be checked with function_exists() before being used.
3.6.0Added the $post parameter.
2.8.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    This always shows the current post status in the labels. This is especially useful when adding many custom post states.

    /**
     * This always shows the current post status in the labels.
     *
     * @param array   $states current states.
     * @param WP_Post $post current post object.
     * @return array
     */
    function custom_display_post_states( $states, $post ) {
    	/* Receive the post status object by post status name */
    	$post_status_object = get_post_status_object( $post->post_status );
    
    	/* Checks if the label exists */
    	if ( in_array( $post_status_object->label, $states, true ) ) {
    		return $states;
    	}
    
    	/* Adds the label of the current post status */
    	$states[ $post_status_object->name ] = $post_status_object->label;
    
    	return $states;
    }
    
    add_filter( 'display_post_states', 'custom_display_post_states', 10, 2 );

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