Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for 'any' post status in get_pages() #8042

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -6233,6 +6233,7 @@ function get_page_uri( $page = 0 ) {
*
* @since 1.5.0
* @since 6.3.0 Use WP_Query internally.
* @since 6.8.0 Added 'any' as an accepted `$post_status`.
*
* @param array|string $args {
* Optional. Array or string of arguments to retrieve pages.
Expand Down Expand Up @@ -6265,7 +6266,8 @@ function get_page_uri( $page = 0 ) {
* Default 0.
* @type string $post_type The post type to query. Default 'page'.
* @type string|array $post_status A comma-separated list or array of post statuses to include.
* Default 'publish'.
* Default 'publish'. If `$post_status` includes 'any' then any status
* post status with 'exclude_from_search' will also be included.
* }
* @return WP_Post[]|false Array of pages (or hierarchical post type items). Boolean false if the
* specified post type is not hierarchical or the specified status is not
Expand Down Expand Up @@ -6316,6 +6318,16 @@ function get_pages( $args = array() ) {
if ( ! is_array( $post_status ) ) {
$post_status = explode( ',', $post_status );
}

if ( in_array( 'any', $post_status ) ) {
$post_status = array_unique(
array_merge(
array_diff( $post_status, array( 'any' ) ),
array_keys( get_post_stati( array( 'exclude_from_search' => false ) ) )
)
);
}

if ( array_diff( $post_status, get_post_stati() ) ) {
return false;
}
Expand Down
Loading