Skip to content

Fix Cmd+K entity search not finding posts in Commands mode - #424

Merged
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
KarunyaChavan:fix/desktop-admin-command-palette-entity-search
Jul 28, 2026
Merged

Fix Cmd+K entity search not finding posts in Commands mode#424
AllTerrainDeveloper merged 3 commits into
WordPress:trunkfrom
KarunyaChavan:fix/desktop-admin-command-palette-entity-search

Conversation

@KarunyaChavan

@KarunyaChavan KarunyaChavan commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

This PR fixes the Cmd+K command palette so typing a post or page title in Commands mode shows matching results you can click or press Enter to open in the editor - matching the behavior of Classic Admin Mode's Cmd+K.

Closes #411

Why?

  • In Classic Admin Mode, pressing Cmd+K and typing a post title instantly showed results and let you open the post editor with one click.
  • Desktop Mode's Cmd+K showed "No commands matching…" instead.
  • Users switching to Desktop Mode expect the same quick-content-search muscle memory to work.
  • The REST API search existed but the results were never fetched, displayed, or made clickable.

What changed?

  • New REST search (_fetchRemoteCommands): When you type plain text in Commands mode, the palette now calls /wp/v2/search (200ms debounced) and turns matching posts/pages into clickable command items.
  • Click handler rewrite: Previously the click handler used findCommand(slug) which only finds registered slash-commands. Entity search results aren't registered commands, so clicks did nothing. Now it looks up by data-index from the live match list instead.
  • Result styling: Entity results get a regular font (not the monospace used for slash-commands) via the new .is-entity-result CSS class, so they visually read as content search results.
  • Admin URL config: Added adminUrl to the assistant config so entity result links resolve to absolute wp-admin/post.php?post=N&action=edit URLs for opening in legacy windows.

Steps for Testing:

  1. Press Cmd+K to open the command palette (make sure you're in Commands mode, not Ask AI)
  2. Type the title of an existing post or page - matching results should appear below the command list
  3. Click a result - it should open the post/page editor in a legacy window
  4. Switch to Ask AI mode and type a natural language question like "How do I create a post?" - pressing Enter should submit the question to the AI, not open a random post

- Fetch posts/pages via `/wp/v2/search` and render as pickable items in both Commands and AI modes.
- Route click handlers through `data-index` lookup instead of `findCommand()` to support unregistered remote results.
- Add `adminUrl` config for absolute admin edit URL construction.
- Visually distinguish entity results from commands with regular font via `.is-entity-result` CSS rule.
@KarunyaChavan
KarunyaChavan marked this pull request as ready for review July 27, 2026 12:45
@KarunyaChavan

Copy link
Copy Markdown
Contributor Author

We implemented entity search (posts/pages) in the Cmd+K palette — type a title, see results, click to Edit. This closes the gap with Classic Admin Mode.

One detail we didn't replicate: Classic mode shows "Edit" as a right-aligned badge on each result row. We left it out because:

  • Each result already shows "Post" or "Page" as a description line below the title
  • Entity results already get a different font (regular vs. monospace for slash-commands) via CSS
  • Adding a third visual indicator felt like clutter

Would you like us to add "Edit" text anyway to match classic mode exactly? Or is the current approach (description + font difference) sufficient?

KarunyaChavan and others added 2 commits July 28, 2026 19:21
- Cover REST search guards (Commands-only, slash-commands, empty input,
AI mode), entity result rendering and styling, click-to-open via windowManager, silent error handling, and token-based staleness.

@AllTerrainDeveloper AllTerrainDeveloper left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would you like us to add "Edit" text anyway to match classic mode exactly? Or is the current approach (description + font difference) sufficient?

We don't necessarily need to replicate everything, if we can improve it :) That's what you did :) Thank you!

And because I tested yours, I found a bug of mine :)
image

I'll quickly fix the theming issue, which is not applied in the command palette

@AllTerrainDeveloper
AllTerrainDeveloper merged commit 274b0b5 into WordPress:trunk Jul 28, 2026
6 checks passed
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.

Cmd+K post search works in Classic Admin but not in Desktop Admin Mode

2 participants