Skip to content

Posts, Post Types: Add a fields argument to get_pages() for page dropdowns - #16341

Open
RafaelFunchal wants to merge 3 commits into
WordPress:trunkfrom
RafaelFunchal:fix/41714-get-pages-dropdown-fields
Open

RafaelFunchal wants to merge 3 commits into
WordPress:trunkfrom
RafaelFunchal:fix/41714-get-pages-dropdown-fields

Conversation

@RafaelFunchal

@RafaelFunchal RafaelFunchal commented Nov 30, 2026 •

Copy link
Copy Markdown

get_pages() loads every page with all of its columns and adds them all to the post cache. Every page dropdown in the admin does this just to print titles, so on sites with thousands of long pages, those screens run out of memory.

  • get_pages() accepts 'fields' => 'dropdown'. It runs the same WP_Query for IDs only, then loads only the columns a dropdown needs. Those rows are cached in post-queries and kept out of the post cache. Without the argument, nothing changes, including the arguments passed to the get_pages_query_args and get_pages filters.
  • Core's page dropdowns opt in: Settings → Reading, the Privacy policy page, Page Attributes, Quick Edit, and the Customizer's page control. wp_dropdown_pages() passes the argument through but doesn't change its default.
  • Settings → Reading checks for one published top-level page before showing the homepage settings, instead of loading every page with get_pages(). The answer is the same. This was Reading Settings: Check for one top-level page instead of loading every page #16340, which on its own didn't lower the screen's peak: the first dropdown did the full load instead.

On a WordPress.com site with about 6,600 long pages, one dropdown went from 797 MB / 3.2 s to 209 MB / 0.6 s, with an identical option list. On a local trunk site with 307 long pages, peak memory went from +17.9 MB to +1.4 MB.

For the whole Reading screen (the check plus both dropdowns) on a local trunk site with 3,000 pages of 20 KB each, peak memory went from +150 MB to +5.3 MB.

Testing:

  • 5 new tests (@ticket 41714). Each fails if I break the part of the change it covers: cache reads, the post cache, page order, the filter fallback, and the argument itself.
  • The post, customize and admin groups pass (3,404 tests).
  • After adding the Reading check: the get_pages(), wp_dropdown_pages() and admin tests pass (1,583 tests).
  • PHPCS reports nothing on the changed lines.

The open questions (naming, compatibility for filter callbacks on the core screens, and whether wp_dropdown_pages() should use this by default) are in the ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/41714

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: investigating the memory problem, drafting the change, tests and description, and running the tests. I reviewed and edited the final code, tests and text.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…dropdowns.

With `'fields' => 'dropdown'`, `get_pages()` runs the same `WP_Query` for IDs only, then loads only the columns a page dropdown needs. The rows are cached separately and kept out of the post cache, so a later `get_post()` still returns the full page. Without the argument nothing changes, including the arguments passed to the `get_pages_query_args` and `get_pages` filters.

See #41714.
…wn fields.

Settings > Reading, the Privacy policy page selector, Page Attributes, Quick Edit and the Customizer's page control only show titles and hierarchy, but loaded every page in full. On sites with thousands of long pages, these screens run out of memory.

See #41714.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rafaelfunchal.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

…screen.

Settings > Reading decided whether to show the homepage settings with `get_pages()`, which loads every published page in full and adds them all to the post cache.

Check for one published top-level page instead. The default, hierarchical `get_pages()` result is non-empty only when such a page exists, and the homepage dropdowns offer the same pages, so the answer is unchanged. With the dropdowns' `fields => 'dropdown'`, the screen no longer loads any page in full.

See #41714.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant