get_post_states example

get_posts( $args )
            );

            foreach ( $posts as $post ) {
                $post_title = $post->post_title;
                if ( '' === $post_title ) {
                    /* translators: %d: ID of a post. */
                    $post_title = sprintf( __( '#%d (no title)' )$post->ID );
                }

                $post_type_label = get_post_type_object( $post->post_type )->labels->singular_name;
                $post_states     = get_post_states( $post );
                if ( ! empty( $post_states ) ) {
                    $post_type_label = implode( ',', $post_states );
                }

                $items[] = array(
                    'id'         => "post-{$post->ID}",
                    'title'      => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ),
                    'type'       => 'post_type',
                    'type_label' => $post_type_label,
                    'object'     => $post->post_type,
                    'object_id'  => (int) $post->ID,
                    

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;

            
$menu_item->object_id        = ! isset( $menu_item->object_id ) ? get_post_meta( $menu_item->ID, '_menu_item_object_id', true ) : $menu_item->object_id;
            $menu_item->object           = ! isset( $menu_item->object ) ? get_post_meta( $menu_item->ID, '_menu_item_object', true ) : $menu_item->object;
            $menu_item->type             = ! isset( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type;

            if ( 'post_type' === $menu_item->type ) {
                $object = get_post_type_object( $menu_item->object );
                if ( $object ) {
                    $menu_item->type_label = $object->labels->singular_name;
                    // Denote post states for special pages (only in the admin).                     if ( function_exists( 'get_post_states' ) ) {
                        $menu_post   = get_post( $menu_item->object_id );
                        $post_states = get_post_states( $menu_post );
                        if ( $post_states ) {
                            $menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
                        }
                    }
                } else {
                    $menu_item->type_label = $menu_item->object;
                    $menu_item->_invalid   = true;
                }

                if ( 'trash' === get_post_status( $menu_item->object_id ) ) {
                    $menu_item->_invalid = true;
                }
Home | Imprint | This part of the site doesn't use cookies.