get_post_stati example

return $counts;
        }

        $query = " SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND post_name = %s GROUP BY post_status";

        $results = (array) $wpdb->get_results( $wpdb->prepare( $query$this->post_type, $this->request_type ), ARRAY_A );
        $counts  = array_fill_keys( get_post_stati(), 0 );

        foreach ( $results as $row ) {
            $counts[ $row['post_status'] ] = $row['num_posts'];
        }

        $counts = (object) $counts;
        wp_cache_set( $cache_key$counts, 'counts' );

        return $counts;
    }

    

    public function establish_loaded_changeset() {
        global $pagenow;

        if ( empty( $this->_changeset_uuid ) ) {
            $changeset_uuid = null;

            if ( ! $this->branching() && $this->is_theme_active() ) {
                $unpublished_changeset_posts = $this->get_changeset_posts(
                    array(
                        'post_status'               => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ),
                        'exclude_restore_dismissed' => false,
                        'author'                    => 'any',
                        'posts_per_page'            => 1,
                        'order'                     => 'DESC',
                        'orderby'                   => 'date',
                    )
                );
                $unpublished_changeset_post  = array_shift( $unpublished_changeset_posts );
                if ( ! empty( $unpublished_changeset_post ) && wp_is_uuid( $unpublished_changeset_post->post_name ) ) {
                    $changeset_uuid = $unpublished_changeset_post->post_name;
                }
            }
parent::__construct(
            array(
                'plural' => 'posts',
                'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
            )
        );

        $post_type        = $this->screen->post_type;
        $post_type_object = get_post_type_object( $post_type );

        $exclude_states = get_post_stati(
            array(
                'show_in_admin_all_list' => false,
            )
        );

        $this->user_posts_count = (int) $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' ) AND post_author = %d",
$where .= $post_type_where;

            $statuswheres = array();
            $q_status     = $q['post_status'];
            if ( ! is_array( $q_status ) ) {
                $q_status = explode( ',', $q_status );
            }
            $r_status = array();
            $p_status = array();
            $e_status = array();
            if ( in_array( 'any', $q_status, true ) ) {
                foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) {
                    if ( ! in_array( $status$q_status, true ) ) {
                        $e_status[] = "{$wpdb->posts}.post_status <> '$status'";
                    }
                }
            } else {
                foreach ( get_post_stati() as $status ) {
                    if ( in_array( $status$q_status, true ) ) {
                        if ( 'private' === $status ) {
                            $p_status[] = "{$wpdb->posts}.post_status = '$status'";
                        } else {
                            $r_status[] = "{$wpdb->posts}.post_status = '$status'";
                        }
global $wpdb;

    if ( ! post_type_exists( $type ) ) {
        return new stdClass();
    }

    $cache_key = _count_posts_cache_key( $type$perm );

    $counts = wp_cache_get( $cache_key, 'counts' );
    if ( false !== $counts ) {
        // We may have cached this before every status was registered.         foreach ( get_post_stati() as $status ) {
            if ( ! isset( $counts->{$status} ) ) {
                $counts->{$status} = 0;
            }
        }

        /** This filter is documented in wp-includes/post.php */
        return apply_filters( 'wp_count_posts', $counts$type$perm );
    }

    $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";

    
'slug'         => array(
                    'description' => __( 'An alphanumeric identifier for the post unique to its type.' ),
                    'type'        => 'string',
                    'context'     => array( 'view', 'edit', 'embed' ),
                    'arg_options' => array(
                        'sanitize_callback' => array( $this, 'sanitize_slug' ),
                    ),
                ),
                'status'       => array(
                    'description' => __( 'A named status for the post.' ),
                    'type'        => 'string',
                    'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
                    'context'     => array( 'view', 'edit' ),
                    'arg_options' => array(
                        'validate_callback' => array( $this, 'check_status' ),
                    ),
                ),
                'type'         => array(
                    'description' => __( 'Type of post.' ),
                    'type'        => 'string',
                    'context'     => array( 'view', 'edit', 'embed' ),
                    'readonly'    => true,
                ),
                

                ),
                'description'    => array(
                    'description' => __( 'Description of template.' ),
                    'type'        => 'string',
                    'default'     => '',
                    'context'     => array( 'embed', 'view', 'edit' ),
                ),
                'status'         => array(
                    'description' => __( 'Status of template.' ),
                    'type'        => 'string',
                    'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
                    'default'     => 'publish',
                    'context'     => array( 'embed', 'view', 'edit' ),
                ),
                'wp_id'          => array(
                    'description' => __( 'Post ID.' ),
                    'type'        => 'integer',
                    'context'     => array( 'embed', 'view', 'edit' ),
                    'readonly'    => true,
                ),
                'has_theme_file' => array(
                    'description' => __( 'Theme file exists.' ),
                    

function wp_edit_posts_query( $q = false ) {
    if ( false === $q ) {
        $q = $_GET;
    }
    $q['m']     = isset( $q['m'] ) ? (int) $q['m'] : 0;
    $q['cat']   = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
    $post_stati = get_post_stati();

    if ( isset( $q['post_type'] ) && in_array( $q['post_type']get_post_types(), true ) ) {
        $post_type = $q['post_type'];
    } else {
        $post_type = 'post';
    }

    $avail_post_stati = get_available_post_statuses( $post_type );
    $post_status      = '';
    $perm             = '';

    
<?php _e( '&mdash; Select &mdash;' ); ?></option> <?php export_date_options(); ?> </select> </fieldset> </li> <li> <label for="post-status" class="label-responsive"><?php _e( 'Status:' ); ?></label> <select name="post_status" id="post-status"> <option value="0"><?php _e( 'All' ); ?></option> <?php             $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
            foreach ( $post_stati as $status ) :
                ?> <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option> <?php endforeach; ?> </select> </li> </ul> <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p> <ul id="page-filters" class="export-filters"> <li> <label><span class="label-responsive">

function wp_get_custom_css_post( $stylesheet = '' ) {
    if ( empty( $stylesheet ) ) {
        $stylesheet = get_stylesheet();
    }

    $custom_css_query_vars = array(
        'post_type'              => 'custom_css',
        'post_status'            => get_post_stati(),
        'name'                   => sanitize_title( $stylesheet ),
        'posts_per_page'         => 1,
        'no_found_rows'          => true,
        'cache_results'          => true,
        'update_post_meta_cache' => false,
        'update_post_term_cache' => false,
        'lazy_load_term_meta'    => false,
    );

    $post = null;
    if ( get_stylesheet() === $stylesheet ) {
        
if ( get_query_var( 'year' ) ) {
            $where .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) );
        }
        if ( get_query_var( 'monthnum' ) ) {
            $where .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) );
        }
        if ( get_query_var( 'day' ) ) {
            $where .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
        }

        $publicly_viewable_statuses = array_filter( get_post_stati(), 'is_post_status_viewable' );
        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared         $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", esc_sql( $publicly_viewable_statuses ) ) . "')" );

        if ( ! $post_id ) {
            return false;
        }

        if ( get_query_var( 'feed' ) ) {
            return get_post_comments_feed_link( $post_idget_query_var( 'feed' ) );
        } elseif ( get_query_var( 'page' ) > 1 ) {
            return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
        }
/** * Retrieves all post statuses, depending on user context. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
    public function get_items( $request ) {
        $data              = array();
        $statuses          = get_post_stati( array( 'internal' => false ), 'object' );
        $statuses['trash'] = get_post_status_object( 'trash' );

        foreach ( $statuses as $slug => $obj ) {
            $ret = $this->check_read_permission( $obj );

            if ( ! $ret ) {
                continue;
            }

            $status             = $this->prepare_item_for_response( $obj$request );
            $data[ $obj->name ] = $this->prepare_response_for_collection( $status );
        }

    do_action_deprecated( 'dbx_post_advanced', array( $post ), '3.7.0', 'add_meta_boxes' );

    /* * Allow the Discussion meta box to show up if the post type supports comments, * or if comments or pings are open. */
    if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) {
        add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
    }

    $stati = get_post_stati( array( 'public' => true ) );
    if ( empty( $stati ) ) {
        $stati = array( 'publish' );
    }
    $stati[] = 'private';

    if ( in_array( get_post_status( $post )$stati, true ) ) {
        /* * If the post type support comments, or the post has comments, * allow the Comments meta box. */
        if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) {
            
$schema['properties']['type'] = array(
            'description' => __( 'The family of objects originally represented, such as "post_type" or "taxonomy".' ),
            'type'        => 'string',
            'enum'        => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom' ),
            'context'     => array( 'view', 'edit', 'embed' ),
            'default'     => 'custom',
        );

        $schema['properties']['status'] = array(
            'description' => __( 'A named status for the object.' ),
            'type'        => 'string',
            'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
            'default'     => 'publish',
            'context'     => array( 'view', 'edit', 'embed' ),
        );

        $schema['properties']['parent'] = array(
            'description' => __( 'The ID for the parent of the object.' ),
            'type'        => 'integer',
            'minimum'     => 0,
            'default'     => 0,
            'context'     => array( 'view', 'edit', 'embed' ),
        );

        
if ( empty( $post_type_object ) ) {
            $post_type_cap    = $post->post_type;
            $read_private_cap = 'read_private_' . $post_type_cap . 's';
        } else {
            $read_private_cap = $post_type_object->cap->read_private_posts;
        }

        /* * Results should include private posts belonging to the current user, or private posts where the * current user has the 'read_private_posts' cap. */
        $private_states = get_post_stati( array( 'private' => true ) );
        $where         .= " AND ( p.post_status = 'publish'";
        foreach ( $private_states as $state ) {
            if ( current_user_can( $read_private_cap ) ) {
                $where .= $wpdb->prepare( ' OR p.post_status = %s', $state );
            } else {
                $where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id$state );
            }
        }
        $where .= ' )';
    } else {
        $where .= " AND p.post_status = 'publish'";
    }
Home | Imprint | This part of the site doesn't use cookies.