Repository navigation
Conversation
`type` selected one entity type or, when omitted, all of them. A caller that wants posts and terms but not attachments had no way to say so, and had to discard the attachments afterwards. That is not equivalent: the merged results are sliced to `perPage` before the caller sees them, so attachments can consume the page and be thrown away, leaving fewer suggestions than asked for. `type` now also accepts an array. `subtype` is ignored for a multi-type search, since it belongs to a single type and cannot be applied unambiguously. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
🤖 PR meta 🤖📦 Bundle sizeSize Change: +12 B (0%) Total Size: 8.21 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
|
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. |
"Cannot be applied unambiguously" undersold it. Validation accepts any registered post type or taxonomy name, so a post type slug reaches the term handler without being rejected and returns nonsense: `type=term&subtype=page` leaks the private `wp_template_part_area` taxonomy and returns more rows than an unscoped term search. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
Two tests did not describe the option. Adds cases for an array of one behaving like the bare type, subtype surviving that case, types outside the array not being searched, attachments when asked for, disablePostFormats still winning over an explicit request, and an empty array searching nothing. Writing them showed the subtype guard was inconsistent: it keyed on Array.isArray, so `[ 'post' ]` dropped a subtype while `'post'` kept it, even though both search exactly one type. It now keys on how many types were requested, since one type is unambiguous however it is spelled. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
Dropping subtype for a multi-type search meant "pages and categories"
could not be expressed at all, only "every post type and every taxonomy".
Sending one subtype to every handler is not an option either: an
unmatched subtype does not degrade, it corrupts. On a test site the term
handler went from 13 results to 16, leaking the private
`wp_template_part_area` and `post_format` taxonomies, while the post
handler silently dropped every page.
So a subtype travels with its type:
type: [ { type: 'post', subtype: 'page' }, { type: 'term' } ]
Every accepted shape normalizes to the same internal list, so the older
forms are unchanged: a bare type with a top level subtype, and an array
of bare types. The top level subtype applies only to a single type given
on its own, since in the array form each entry carries its own.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
Mapping the results to `kind` produced [ 'post-type', 'taxonomy', 'taxonomy' ], which reads like a duplicate until you go and check the mock. It is one result from the post search and two from the term search. Assert the titles alongside the kinds so the test says that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
Allowing both `[ 'post' ]` and `[ { type: 'post' } ]` meant answering
whether the top level subtype applied to a bare entry, which is the
ambiguity this shape existed to remove. An array now takes entries only,
and the normalization is two lines: one type becomes one entry carrying
the top level subtype, a list is already entries.
Also covers several subtypes for one type, which the REST parameter has
always accepted and nothing tested. addQueryArgs indexes array values, so
the mock needed the subtype[0] form.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
The array of types grew into entries carrying their own subtypes, which raised a question at every step: whether a bare entry inherited the top level subtype, what an empty array meant, and whether `type` was still an honest name for a list of search descriptions. None of that was needed. The problem was never selecting types, it was that a caller cannot use every type and had to discard results after the merge had already cut them to `perPage`. `exclude` says exactly that and nothing more, leaves `type` and `subtype` untouched, and takes a new handler into account by default rather than being a list to keep updated. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
`subtype` was widened to accept an array while `type` could hold entries that carried their own. Nothing needs that now, so it goes back to a string. `SearchType` stays, since `exclude` needs the union named and repeating a four member union twice is worse, but it is no longer exported. Naming it is an implementation detail, not a new public type. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BLn4hqAvfFyNGLLgsSkCcv
| * Filters by search type. | ||
| */ | ||
| type?: 'attachment' | 'post' | 'term' | 'post-format'; | ||
| type?: SearchType; |
There was a problem hiding this comment.
What if this was an array like ['attachment' | 'post' | 'term' | 'post-format'] so if you want to exclude one you just remove it from the array?
There was a problem hiding this comment.
We could do that, but then what do we do about subType? If you pass an array of types and a string for subType, does the subType get passed to each query? Excluding was the safest next step, but I think this whole API is a bit busted. For example, the perPage and page don't work correctly right now.
If you pass 20 perPage results for page 2, what you're doing is a page 2 search for all of the types (four diffrent types; 'attachment' | 'post' | 'term' | 'post-format') and then receiving the 20 best matches of the 80 results back. When you request page 3, you're getting the page 3 search results of each of them, but only returning 20 out of the possible pool of 80 back. Each page, you're actually losing 60 results each time you move forward, so it's already a little fuzzy. Maybe we should rethink how this whole API works and not add an exclusion for now.
That said, maybe the above is the better approach. Do we really want to re-search the worst results from our search pool again?
I'm wary of making any big changes here right now, as each time I start making a change I run into something that makes me rethink it. Also, I think what is being saved by excluding types isn't really that essential to #82985.
|
I'm going to close this PR for now. I'm unsure if it's the right move. |
Adds the `exclude` option from #83084 to `fetchLinkSuggestions`, and uses it from the Navigation Link UI. An attachment is a file rather than a destination, and a post format is a way of styling a post rather than something to navigate to. Ranking them last keeps them out of the way, but they are still fetched and still take room in a list that is cut to `perPage` before the caller sees it. Excluding them frees that room for results a Navigation can use. The ranking stays, because it still applies to every other `LinkControl` in the editor, none of which excludes anything. A Post Format Link searches post formats, so it keeps them: the exclusion drops whichever types the link does not search for itself. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VbpgaY282xpLjwA8aQv3x9
…y type Replaces the exclusion added for Navigation with a ranking that keeps every type reachable, and makes the order a caller's to choose. `DEFAULT_TYPE_ORDER` ranks pages, then categories, posts, tags, attachments and post formats. `typeOrder` overrides it; a caller may name every type, or only the ones it wants to lead with, and the rest keep their default places below them. The Navigation Link UI names its own type, so each link leads with the kind of thing it is. Nothing is dropped. An attachment is reachable by typing its exact title, which is the only signal that lifts a result past the rank of its type. Beginning with the search term orders titles within a type but never raises one type above another, so an attachment called "Coffee Cup Photo" cannot pass a page called "Our Coffee". Removes the `exclude` option, which no caller now uses; #83084 proposes it separately. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VbpgaY282xpLjwA8aQv3x9
What?
Adds an
excludeoption to__experimentalFetchLinkSuggestions:Why?
An unscoped search covers every type. In #82985, we want to search all types except unlikely ones to be included for navigation links (i.e., attachments)
How?
Add an
exclude: []prop and use it to exclude our type.Testing Instructions
The change is to a JavaScript API, so this is exercised from the browser console. Use a site with a media library.
media. On the site used above, 5 of 7.exclude.To see the Navigation case from the "Why" section: add a Navigation block, use the appender, choose Add block → Custom Link, and search "image".
Automated coverage
🤖 Generated with Claude Code