REST API: add WP_REST_Posts_Controller route to fetch page counts #67719
+388
−25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Alternative to #66294
Extends
WP_REST_Posts_Controller
with a new route to fetch page countsThis PR only affects the
page
post type.In the Core sync, all post types that inherit from
WP_REST_Posts_Controller
will get the/count
route.Why?
The need for a performant post counts check for the block editor. See: #65223 (comment)
Contrast this with
$query->found_posts
which returns the total count for a specific query only and would degrade performance givenn
posts.How?
Via
wp/v2/pages/count
, the editor can fetch the total number of post counts.This is done using wp_count_posts.
Testing Instructions
Run tests:
npm run test:unit:php:base -- --filter Gutenberg_Test_REST_Posts_Controller
Examples to run in the browser console (in the editor):
Also add a custom post status and ensure it appears in the response: