Repository navigation
Posts, Post Types: Add a fields argument to get_pages() for page dropdowns - #16341
RafaelFunchal wants to merge 3 commits into
Conversation
…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.
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…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.
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 sameWP_Queryfor IDs only, then loads only the columns a dropdown needs. Those rows are cached inpost-queriesand kept out of the post cache. Without the argument, nothing changes, including the arguments passed to theget_pages_query_argsandget_pagesfilters.wp_dropdown_pages()passes the argument through but doesn't change its default.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:
@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.post,customizeandadmingroups pass (3,404 tests).get_pages(),wp_dropdown_pages()and admin tests pass (1,583 tests).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.