Skip to content

Add core/terms-query ability - #1084

Closed
muneeb-ashraf wants to merge 7 commits into
WordPress:developfrom
muneeb-ashraf:add/core-terms-query
Closed

muneeb-ashraf wants to merge 7 commits into
WordPress:developfrom
muneeb-ashraf:add/core-terms-query

Conversation

@muneeb-ashraf

@muneeb-ashraf muneeb-ashraf commented Oct 1, 2026 •

Copy link
Copy Markdown

What?

Closes #1063

Adds a read-only core/terms-query ability, so agents and MCP clients can see which categories, tags, and other terms exist without guessing names or falling back to REST.

Why?

The 7.2 roadmap names taxonomies among the read-only resources to cover, and nothing in the current core/*-query set exposes terms. Agents that draft or classify content need the real term list.

How?

Built on the core/users-query / core/content-query pattern, and gated behind the Custom Abilities experiment in the same way (Gated\Terms_Query, added to Gated_Abilities).

Exposure follows the model agreed in #1063: a taxonomy is readable only when it opts in with show_in_abilities, like post types for core/content-query. show_in_rest alone does not expose a taxonomy. Show_In_Abilities marks category and post_tag (not post_format), with the same rules as post types: an explicit false is respected, and the polyfill stands down once core declares the flag on WP_Taxonomy. With no exposed taxonomy, the ability is not registered.

Modes (a oneOf, so mixed arguments are rejected):

  • a single term by id (optional taxonomy must match),
  • a single term by taxonomy + slug,
  • a collection for one taxonomy, filtered by search, parent, post, hide_empty, include, exclude, with orderby / order, page / per_page (default 10, max 100), returning terms, total, total_pages. hide_empty defaults to true, so a listing returns terms in use; with post it defaults to false, since a post's own terms can have a zero count while the post is unpublished.

Fields: id, name, slug, taxonomy, description, parent (hierarchical only, as in REST), count, link. The default set is id, name, slug, taxonomy, parent, count. Term meta is not exposed; it would need its own opt-in.

Permissions:

  • authenticated user required, like the sibling query abilities;
  • only taxonomies exposed with show_in_abilities;
  • post mirrors WP_REST_Terms_Controller: an unknown post returns terms_post_invalid_id (400), and a post that does not use the taxonomy or that the user cannot read returns terms_forbidden_context.

Apart from the hide_empty default, the collection query follows WP_REST_Terms_Controller::get_items(): parent only applies to hierarchical taxonomies, the taxonomy's registered args are merged in unless post is set, and totals come from wp_count_terms() with the same arguments.

Not included: a core/taxonomies-query companion. As noted on #1063, the exposed taxonomies are listed in the input schema.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Code and tests.

Testing Instructions

tests/Integration/Includes/Abilities/Terms/TermsTest.php (31 tests) covers the issue's acceptance list and the opt-in model: curated and opted-in custom taxonomies, a show_in_rest-only taxonomy being denied, an explicit opt-out, no registration without exposed taxonomies, hierarchical listing with parent, terms for a public, a private, and a missing post (with the error codes), exclude, pagination totals, meta being rejected, the REST string forms of inputs, the hide_empty defaults, and rejection of mixed modes. Show_In_AbilitiesTest has 6 new taxonomy tests.

npm run test:php -- --filter 'TermsTest|Show_In_AbilitiesTest|Gated_AbilitiesTest'
npm run test:php:multisite -- --filter 'TermsTest|Show_In_AbilitiesTest|Gated_AbilitiesTest'

Both pass locally (single site and multisite). The full PHPUnit suite shows the same failures as develop and no new ones, and PHPCS and PHPStan are clean on the changed files.

Manual check: enable the Custom Abilities experiment, then run core/terms-query from the Abilities Explorer with {"taxonomy":"category"}, or call it through the MCP Adapter.

Changelog Entry

Added - core/terms-query ability for reading categories, tags, and other taxonomy terms.

🤖 Generated with Claude Code

Open WordPress Playground Preview

Adds a read-only `core/terms-query` ability, gated behind the Custom
Abilities experiment like `core/users-query` and `core/content-query`.

It reads a single term by ID or by taxonomy and slug, or a paginated
collection of one taxonomy's terms filtered by search, parent, attached
post, emptiness, or included IDs, with `total` and `total_pages`.

Permissions mirror WP_REST_Terms_Controller: only `show_in_rest`
taxonomies, and terms of a post require the post to be publicly
viewable or readable. Taxonomies that are not publicly viewable also
require the taxonomy's `assign_terms` capability.

See WordPress#1063.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
@muneeb-ashraf
muneeb-ashraf requested a review from a team October 1, 2026 08:04
@github-actions

github-actions Bot commented Oct 1, 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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: muneeb-ashraf <muneebashraf@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: whyisjake <whyisjake@git.wordpress.org>

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

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.91183% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.36%. Comparing base (6bc5600) to head (9f0ed4b).

Files with missing lines Patch % Lines
includes/Abilities/Terms/Terms.php 98.26% 7 Missing ⚠️
includes/Abilities/Show_In_Abilities.php 91.30% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #1084      +/-   ##
=============================================
+ Coverage      85.05%   85.36%   +0.30%     
- Complexity      4836     4952     +116     
=============================================
  Files            190      192       +2     
  Lines          17971    18402     +431     
=============================================
+ Hits           15286    15708     +422     
- Misses          2685     2694       +9     
Flag Coverage Δ
unit 85.36% <97.91%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Adds tests for object and REST string input, direct execution of
unreadable requests, malformed permission input, and the hook and
category fallback, which the first round of tests left uncovered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
muneeb-ashraf and others added 3 commits October 5, 2026 03:29
Following the review on WordPress#1063, taxonomies are exposed to `core/terms-query`
only when they opt in with `show_in_abilities`, the model `core/content-query`
uses for post types. `show_in_rest` alone no longer exposes a taxonomy, since
abilities skip the REST filters and callbacks that opt-in assumed.

- Show_In_Abilities also marks `category` and `post_tag`, with the same
  explicit opt-out and core stand-down rules as post types.
- The ability is not registered when no taxonomy is exposed.
- Remove the `meta` field; term meta needs its own opt-in later.
- Add `exclude`.
- An invalid or unreadable `post` filter returns `terms_post_invalid_id` or
  `terms_forbidden_context`, like the REST terms controller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
Resolves the Gated_AbilitiesTest import conflict from the
`core/settings-get` rename (WordPress#1087).

Also marks Terms_Query as depending on core-object exposure, since
`core/terms-query` now reads the `show_in_abilities` flag that
Show_In_Abilities sets on `category` and `post_tag`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
Matches the `core/content-query` changes in WordPress#1122 and WordPress#1123: set the
`public` meta flag added in WordPress 7.1, and write multi-line comments
as block comments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
@jeffpaul

Copy link
Copy Markdown
Member

@jorgefilipecosta @gziolo waiting on your reviews here

@gziolo

gziolo commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

@jorgefilipecosta works on the same ability in #1099. I will let him decide how to proceed.

@jeffpaul jeffpaul mentioned this pull request Oct 28, 2026
31 of 46 tasks
@dkotter dkotter modified the milestones: 1.5.0, 1.6.0 Oct 29, 2026
whyisjake added a commit that referenced this pull request Nov 6, 2026
Stacked on #1004. Part of the follow-up on [jeffpaul's
review](#1004 (comment)),
items 5–7: the demo prompts ("Find a gap", "Audit content") need to list
recent posts and filter them, and the workspace could only search by
keyword. This adds the read tools those prompts need.

## What changed

**`ai/search-content` lists and filters, not just searches.**
- **`search` is optional.** Without it, the newest posts come first.
- **New optional inputs:**
- `orderby`: `relevance` or `date`. It defaults to relevance with a
search term and to date without one.
- `tax`: `{ taxonomy, terms }`, a public taxonomy and up to 20 term
slugs or names.
- `date_after` / `date_before`: `YYYY-MM-DD`, with both end days
included.
  - `has_featured_image`: `true` or `false`.
- **Each row also returns** `terms` (names keyed by taxonomy) and
`has_featured_image`.
- **Unchanged:** the per-post read check, the `examined`/`withheld`
counts the transcript's trace reads, and the 20-post page cap.

**A filter never widens the list.** Each of these is an error rather
than being ignored:
- a taxonomy the ability doesn't list (an unknown or private one);
- a `tax` value that isn't an object;
- a date that isn't a real day, such as `2026-02-31`. WP_Date_Query
would otherwise read it as 1970-01-01.

A term the taxonomy doesn't have matches no posts.

Only publicly viewable taxonomies attached to a post type exposed to
abilities can be filtered by or appear in a row's `terms`. A post has a
featured image when its `_thumbnail_id` is a positive number, the same
test `has_post_thumbnail()` uses for the row. Boolean and list inputs
are read as typed values or as the strings a GET request carries.

**New `ai/list-terms`.**
- Lists the terms of those same public taxonomies, with each term's
`name`, `slug` and published-post `count`.
- Defaults to categories and tags. `orderby` is `name` or `count`,
`hide_empty` defaults to true, and `per_page` is capped at 100.
- It's read-only, not destructive, `open_world: false`, and requires an
authenticated user.
- It stands in until `core/terms-query` (#1099 / #1084) lands here, as
the plan says.

**Tool list and policy:**
- Both abilities are on `Tool_Selector::DEFAULT_CANDIDATES`.
- `core/settings-get`, the name WordPress 7.2 gives the settings reader,
is added to `Tool_Policy::NEVER_ADMITTED` beside the old
`core/read-settings` (plan KTD9). The gap was hidden only because core
leaves out `open_world`.

**Structure.** The filter clauses and taxonomy discovery live in a new
`Search_Filters` class, shared by both abilities and resolved once per
call. `docs/experiments/ai-workspace.md` covers the new inputs, the new
ability and the never-admitted list.

## Tests

PHPUnit, `Search_ContentTest`:
- New:
  - "test_without_a_search_term_lists_newest_first"
  - "test_search_orders_by_relevance_unless_asked_for_date"
- "test_filters_by_term_date_range_and_featured_image": the fixtures
cover every combination of tag, year and thumbnail.
  - "test_date_range_includes_both_end_days"
  - "test_rows_carry_terms_and_featured_image"
  - "test_unknown_term_matches_no_posts"
  - "test_unknown_or_private_taxonomy_is_a_validation_error" (guard)
-
"test_execute_callback_refuses_an_unknown_taxonomy_without_schema_validation"
  - "test_listing_without_a_term_withholds_an_unreadable_post"
  - "test_an_impossible_date_is_refused"
  - "test_execute_callback_refuses_a_tax_filter_that_is_not_an_object"
  - "test_a_zero_thumbnail_id_counts_as_no_featured_image"
  - "test_private_taxonomy_terms_stay_off_rows" (guard)
- Updated:
  - "test_input_schema_caps_per_page": `search` is no longer required.
-
"test_search_with_no_term_reports_no_withheld_count_when_a_post_type_was_dropped":
comment wording only.

PHPUnit, new `List_TermsTest`, 8 tests:
- read-only and local annotations;
- ordering by count;
- leaving empty terms out by default;
- categories and tags by default;
- unknown and private taxonomies refused, through the schema and the
callback;
- the cap and total;
- a logged-out request refused.

PHPUnit, new `Search_Content_RestTest`, 2 guard tests:
- "test_search_filters_are_honoured_from_a_query_string"
- "test_list_terms_reads_its_inputs_from_a_query_string"

PHPUnit, `Tool_PolicyTest`:
- New: "test_settings_get_is_withheld_with_perfect_annotations".
- Updated:
"test_shipped_withheld_list_covers_the_sensitive_core_abilities".

`Tool_PolicyTest` and `Tool_SelectorTest` now include `ai/list-terms` in
the curated surface they assert against.

What failed before the change:
- On #1004's code, 11 search and policy tests fail, and `List_TermsTest`
can't load without its class.
- On the first commit (04bddc8), the impossible-date, non-object-`tax`
and zero-thumbnail tests fail.
- The tests marked "(guard)" pass on the earlier code too:
- The unknown-taxonomy test passes because the old schema refused any
`tax` input.
- The two REST tests pass because, on WordPress 7.1.4, the abilities
REST endpoint already converts query-string values to the schema's
types.
- The private-taxonomy test passes because the first commit already kept
those terms off the row.

Also run, on WordPress 7.1.4:
- **Full PHPUnit suite:** 3091 tests passed, 57 skipped. After one final
type-narrowing change for PHPStan, I re-ran only the 53 search and terms
tests, which pass.
- **e2e:** the `ai-workspace*` specs, plus the Abilities Explorer and
custom abilities specs. 45 passed (Chromium).
- **PHPStan:** no errors.
- **phpcs:**
  - clean on the changed source files;
- `Tool_PolicyTest` and `Tool_SelectorTest` have the same counts as the
base;
- the new `Search_Content_RestTest` has the same 3 errors as the
existing `Content_RestTest`, from the same REST-server setup.

Not covered:
- The plan's live check isn't done. It asks the "Find a gap" and "Audit
content" prompts, on a seeded site, to produce real tool calls that
return the expected posts. That needs a live model, and the e2e suite
mocks the provider. U10 covers the demo prompts end to end.
- The 20-term cap on a `tax` filter has no test.
- WordPress 7.0.x isn't covered. The REST coercion above was checked on
7.1.4 only, so the string-input parsing is what covers older cores.

## Code review

ce-code-review ran at full depth on the first commit (04bddc8), run
`20261105-103226-768518a0`.
- **Reviewers:** correctness, security, adversarial, testing,
maintainability, performance and API contract.
- **Not run:** the cross-model pass, because no other provider's CLI is
installed, so the adversarial lens ran in-process. There are no project
standards files on this branch.
- **Verdict:** "Ready with fixes". The validator confirmed three
findings, all addressed in 54a0d3e:
- **P1:** `Search_Content.php` grew from 1008 to 1276 lines. The filter
logic moved into `Search_Filters`, and the file is now 1142 lines. The
remaining growth is the new input and output schema.
- **P2:** string `has_featured_image` and comma-separated `tax.terms`
were dropped. Both are now read as typed values or strings.
- The validator confirmed this in the code, for callers that skip schema
validation.
- Through REST on WordPress 7.1.4 it doesn't reproduce: the new REST
tests pass on the first commit as well.
    - REST on 7.0.x wasn't measured.
- **P3:** `ai/list-terms` ignored string `hide_empty` and `taxonomy`.
Fixed the same way.
- **Residual risks the review kept:** all addressed in 54a0d3e:
  - duplicated taxonomy discovery;
  - per-row recomputation;
  - impossible dates;
  - a non-object `tax`;
  - the featured-image filter and row flag disagreeing on `0`.

One more: the `core/settings-get` name couldn't be checked against the
local wordpress-develop checkout. It is the name this plugin's 1.5.0
sync with WordPress 7.2 uses.

AI assistance: Yes. Tool(s): Claude Code (Claude Opus 5.5). Used for:
implementing the change and its tests, which I reviewed.

I've reviewed the changes, understand them and can explain them under
review. They have all been tested locally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- wp-playground-preview:start -->
<a
href="https://playground.wordpress.net?blueprint-url=data:application/json,%7B%22preferredVersions%22%3A%7B%22wp%22%3A%22latest%22%7D%2C%22login%22%3Atrue%2C%22landingPage%22%3A%22%2Fwp-admin%2Fadmin.php%3Fpage%3Dai-wp-admin%22%2C%22steps%22%3A%5B%7B%22step%22%3A%22installPlugin%22%2C%22pluginData%22%3A%7B%22resource%22%3A%22url%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.life-white.uk%2FWordPress%2Fai%2Freleases%2Fdownload%2Fci-artifacts%2Fpr-1296-54a0d3ecca1a243cad855c3f65fbfe074dd5b46b.zip%22%7D%7D%5D%7D"
target="_blank" rel="noopener noreferrer">
<img
src="https://raw.githubusercontent.com/adamziel/playground-preview/refs/heads/trunk/assets/playground-preview-button.svg"
alt="Open WordPress Playground Preview" width="220" height="57" />
</a>
<!-- wp-playground-preview:end -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
muneeb-ashraf and others added 2 commits November 10, 2026 20:06
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collections now default hide_empty to true, so a listing returns terms in
use. A post's own terms keep the old default, since they can have a zero
count while the post is unpublished. Only a show_in_abilities value of true
exposes a taxonomy, matching how develop now normalizes post types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeffpaul

Copy link
Copy Markdown
Member

Closing in favor of WordPress/abilities#10.

@jeffpaul jeffpaul closed this Nov 17, 2026
@jeffpaul jeffpaul removed this from the 1.6.0 milestone Nov 17, 2026
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.

Add a core/terms-query ability (taxonomies, categories, tags)

4 participants