Skip to content

REST API: Add item counts to the page view list in the view config endpoint - #14070

Open
im3dabasia wants to merge 5 commits into
WordPress:trunkfrom
im3dabasia:backport/gb-82247-view-list-counts
Open

im3dabasia wants to merge 5 commits into
WordPress:trunkfrom
im3dabasia:backport/gb-82247-view-list-counts

Conversation

@im3dabasia

Copy link
Copy Markdown

Backports the PHP changes from WordPress/gutenberg#82247. The JS ships through the package sync.

What

GET /wp/v2/view-config?kind=postType&name=page now adds a count to each view list entry whose total a status count can answer:

  • A view without filters counts every status but trash.
  • A view whose only filter is on status (is / isAny) counts those statuses.
  • A view narrowed by anything else (another filter, or a search) gets no count, so it never shows a total that doesn't describe it.

The counts are added in WP_REST_View_Config_Controller::get_items() after every get_entity_view_config_* filter has run, so they describe the final view list, including views added or changed by plugins. One wp_count_posts( 'page', 'readable' ) call supplies every count, which keeps private pages the current user can't read out of the totals. The item schema now includes view_list[].count.

Why

Users can't tell how many drafts or pending items exist without opening each tab, while classic wp-admin shows these counts. This adds the server side of the status tab counts in the site editor's post list.

Files

  • src/wp-includes/view-config.php: adds _wp_add_counts_to_view_list() and _wp_get_view_list_entry_statuses().
  • src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php: adds the counts in get_items() and count to the item schema.
  • tests/phpunit/tests/rest-api/rest-view-config-controller.php: three count tests, and test_get_items_matches_underlying_config now expects the counts.

Testing Instructions

  1. Have a few pages in different statuses (for example 2 drafts, 1 published, 1 in the trash).
  2. Open the site editor and run this in the browser console:
    await wp.apiFetch( { path: '/wp/v2/view-config?kind=postType&name=page' } )
  3. Confirm each entry in view_list has a count matching its status, and that all counts every page except trashed ones.
  4. Run the tests: npm run test:php -- --group view-config

Use of AI Tools

Ported with Claude Code (Claude Opus 5.5). I reviewed every change and ran the tests locally.

@github-actions

github-actions Bot commented Oct 7, 2026 •

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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props im3dabasia1, mukesh27.

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

@github-actions

github-actions Bot commented Oct 7, 2026

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.

@mukeshpanchal27

Copy link
Copy Markdown
Member

Do we have Trac ticket for this backport?

@im3dabasia

Copy link
Copy Markdown
Author

Do we have Trac ticket for this backport?

Hey! Nope, this doesn’t have it as of now. In the past, I’ve had trouble creating a Trac ticket. I don’t see the “Submit” button to create a new ticket. I’ll check if I can create a ticket for this regardless.

@github-actions

Copy link
Copy Markdown

Trac Ticket Missing

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook.

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.

2 participants