Make WordPress Core

Opened 9 years ago

Last modified 6 weeks ago

#40650 new enhancement

get_pages() should accept 'any' among it's post_status arg

Reported by: pbiron's profile pbiron Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.4
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

WP_Query::get_posts() accepts 'any' among it's $post_status $query_vars and I think get_pages() should do the same.

I've combed through the 4.7.4 core code and can't find any place where this enhancement would break existing code.

Attachments (1)

40650.diff (1.7 KB) - added by pbiron 9 years ago.

Download all attachments as: .zip

Change History (10)

@pbiron
9 years ago

#1 @pbiron
9 years ago

  • Keywords has-patch added

#2 @pbiron
9 years ago

FYI: The patch I've attached is loosely based on how 'any' is handled in WP_Query()::get_posts(), but since get_pages() is implemented very differently from WP_Query::get_posts() is kind of different.

#3 @pbiron
9 years ago

The note about me combing through the 4.7.4 core code is my signal that someone who knows the history of how get_pages() has been used in core in previous versions should check that my patch doesn't break previous versions of core if this patch would be backported.

#4 @pbiron
9 years ago

My immediate need for this request is a use of wp_dropdown_pages() on a post_type that uses custom post_stati and I was surprised to learn that I couldn't use 'any' to include posts with these custom post stati.

#5 @pbiron
9 years ago

  • Summary changed from get_pages() should accept 'any' among it's post_stautus arg to get_pages() should accept 'any' among it's post_status arg

#6 @spacedmonkey
3 years ago

  • Keywords needs-refresh added

@pbiron This patch will have to be refreshed now #12821 has been committed.

This ticket was mentioned in PR #8042 on WordPress/wordpress-develop by @sukhendu2002.


16 months ago
#7

  • Keywords needs-refresh removed

#8 @sukhendu2002
9 months ago

  • Keywords has-unit-tests needs-testing added

#9 @ozgursar
6 weeks ago

  • Keywords needs-testing removed

Patch Testing Report

Patch Tested: https://github.com/WordPress/wordpress-develop/pull/8042

Environment

  • WordPress: 7.0-beta2-61752-src
  • PHP: 8.2.29
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 145.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.4
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.1

Steps taken

  1. Using WordPress Develop environment run the wp cli command below. Change the container name wordpress-develop-cli-1 if necessary.
docker exec wordpress-develop-cli-1 wp eval 'print_r( get_pages( [ "post_status" => "any" ] ) );' --allow-root
  1. Confirm that no output is printed
  2. Apply the patch and run the same command
  3. Confirm that get_pages() returns a WP_Post Object
  4. ✅ Patch is solving the problem

Expected result

  • Calling get_pages( [ 'post_status' => 'any' ] ) should return pages of all statuses (publish, draft, private, etc.), consistent with how WP_Query handles the 'any' keyword. After applying the patch from PR 8042, the function returns a populated array of WP_Post objects spanning all post statuses, confirming the patch is solving the problem.

Screenshots/Screencast with results

Before
https://i.imgur.com/531lBfm.png

After
https://i.imgur.com/LDtppmv.png

Note: See TracTickets for help on using tickets.