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

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


Parameters Parameters

$post_states

(string[]) An array of post display states.

$post

(WP_Post) The current post object.



Top ↑

Source Source

File: wp-admin/includes/template.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
3.6.0 Added the $post parameter.
2.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by Pixelbart

    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.