-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
REST API: add WP_REST_Posts_Controller route to fetch page counts #67719
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Extend post type controller to return total post count Alternative to #66294 Extend post type controller to return total post count
9505fde
to
54bfc80
Compare
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: