Skip to content

Abilities API: Add the core/terms-query ability - #16102

Open
jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:add/term-abilities
Open

jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:add/term-abilities

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Shape from WordPress/abilities#22. Same approach as #16028.

This PR adds the core/terms-query ability to the content category, for the taxonomies that set show_in_abilities:

  • core/terms-query takes { where, fields, pagination } and returns { items, pagination } with the totals. where.taxonomy is required, and ids, slugs, parent, post and hide_empty filter the terms.
  • The ability requires a logged-in user. With where.post, the user must be able to read the post.

As suggested in review, core/term-create, core/term-update and core/term-delete moved to their own PR, stacked on this one: #16409

Outside the new WP_Abilities_Terms class:

  • register_taxonomy() accepts a new show_in_abilities argument, stored in WP_Taxonomy::$show_in_abilities. It is false by default and true for category and post_tag.
  • wp_register_core_abilities() loads the class and registers the ability.

Querying the top-level categories, two per page:

await wp.apiFetch( {
	path: wp.url.addQueryArgs( '/wp-abilities/v1/abilities/core/terms-query/run', {
		input: {
			where: { taxonomy: 'category', parent: 0 },
			fields: [ 'name', 'slug', 'count' ],
			pagination: { per_page: 2 },
		},
	} ),
} );
{
	"items": [
		{ "id": 2, "name": "News", "slug": "news", "count": 1 },
		{ "id": 5, "name": "Product updates", "slug": "updates", "count": 0 }
	],
	"pagination": { "total": 3, "total_pages": 2 }
}

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

Testing

Verify unit tests are passing:

npm run test:php -- --group 66743

Or run the example above in the editor console as a logged-in user.

AI disclosure: the change and tests were drafted with AI assistance (Claude Code).

@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.

@jorgefilipecosta jorgefilipecosta added the Core abilities Core abilities related tasks label Nov 19, 2026
@jorgefilipecosta jorgefilipecosta moved this from Todo to In progress in Core abilities Nov 19, 2026
@jorgefilipecosta jorgefilipecosta self-assigned this Nov 19, 2026
@jorgefilipecosta
jorgefilipecosta marked this pull request as ready for review November 20, 2026 15:13
@jorgefilipecosta jorgefilipecosta moved this from In progress to Neeeds review in Core abilities Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 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.

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

Props jorgefilipecosta, gziolo.

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.

@gziolo gziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! I finished my review of core/terms-query and left my comments inline. Thank you also for the quick fix for the slugs.

I recommend splitting this PR. It could keep core/terms-query together with the show_in_abilities argument for taxonomies. The core/term-create, core/term-update and core/term-delete abilities could move to a follow-up PR. This is the process we followed in the WordPress 7.2 cycle, where the read abilities landed first. This way the read part can land much faster, before the writes.

For the query, the two comments that matter most to me are the totals with hide_empty and the post types accepted by where.post. The other comments are low priority.

@github-actions

This comment has been minimized.

Adds `core/terms-query`, which lists the terms of a taxonomy exposed to abilities, and the `show_in_abilities` argument of `register_taxonomy()`, `true` for `category` and `post_tag`.

See #66743.
@jorgefilipecosta jorgefilipecosta changed the title Abilities API: Add the core/terms-query, core/term-create, core/term-update and core/term-delete abilities Abilities API: Add the core/terms-query ability Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core abilities Core abilities related tasks

Projects

Status: Neeeds review

Development

Successfully merging this pull request may close these issues.

2 participants