The get_page_statuses() WordPress PHP function retrieves all of the supported page statuses in WordPress.
Usage
$statuses = get_page_statuses(); print_r($statuses);
Parameters
This function has no parameters.
More information
See WordPress Developer Resources: get_page_statuses()
Examples
Display All Page Statuses
Retrieve all page statuses and display them.
$statuses = get_page_statuses(); foreach ($statuses as $status => $description) { echo "**{$status}**: {$description}<br />"; }
Check if Page Status Exists
Determine if a specific page status exists.
function is_valid_page_status($status) { $statuses = get_page_statuses(); return array_key_exists($status, $statuses); } $status_to_check = 'draft'; if (is_valid_page_status($status_to_check)) { echo "The status '{$status_to_check}' is valid."; } else { echo "The status '{$status_to_check}' is not valid."; }
Count the Number of Pages with a Specific Status
Count the number of pages with a specific status, such as ‘draft’.
function count_pages_with_status($status) { $args = array( 'post_type' => 'page', 'post_status' => $status, 'nopaging' => true, ); $query = new WP_Query($args); return $query->found_posts; } $status_to_count = 'draft'; echo "There are " . count_pages_with_status($status_to_count) . " pages with the '{$status_to_count}' status.";
Filter Pages by Status
Display a list of pages filtered by a specific status, such as ‘private’.
function list_pages_with_status($status) { $args = array( 'post_type' => 'page', 'post_status' => $status, ); $query = new WP_Query($args); if ($query->have_posts()) { echo "<ul>"; while ($query->have_posts()) { $query->the_post(); echo "<li><a href='" . get_permalink() . "'>" . get_the_title() . "</a></li>"; } echo "</ul>"; } else { echo "No pages found with the '{$status}' status."; } wp_reset_postdata(); } $status_to_filter = 'private'; list_pages_with_status($status_to_filter);
Display Page Status in Admin Columns
Add a custom column to the WordPress admin area, showing the page status for each page.
function add_page_status_column($columns) { $columns['page_status'] = 'Page Status'; return $columns; } add_filter('manage_pages_columns', 'add_page_status_column'); function display_page_status_column($column_name, $post_id) { if ($column_name == 'page_status') { $post = get_post($post_id); $statuses = get_page_statuses(); echo $statuses[$post->post_status]; } } add_action('manage_pages_custom_column', 'display_page_status_column', 10, 2);