Skip to content

Add an ability that returns related posts Query Loop markup - #148

Open
fabiankaegy wants to merge 22 commits into
feature/abilities-agent-guidancefrom
feature/abilities-related-query-block
Open

fabiankaegy wants to merge 22 commits into
feature/abilities-agent-guidancefrom
feature/abilities-related-query-block

Conversation

@fabiankaegy

Copy link
Copy Markdown
Member

Description

Stacked on #147.

Pointing agents at the Query Loop only helps if they can build one, and getting the markup right by hand is hard. The PHP render path reads query.relationshipQuery. The editor extension derives that from showRelated and relationshipKey in a useEffect, so it only runs when someone opens the block in the editor. An agent that writes {"showRelated":true} gets a Query Loop that doesn't filter at all.

This adds content-connect/get-related-query-block. It takes post_id, rel_key, an optional post_type (defaults to the relationship's first related type) and per_page (default 3). It returns:

  • markup: a core/query > core/post-template > core/post-title block, ready to insert into the post's content.
  • attributes: the core/query attributes, for clients that build blocks as objects.

The attributes match what the editor extension stores, including orderByRelationship for sortable relationships. I checked this in the editor: the markup opens as a valid block, the extension leaves it untouched (the post isn't marked dirty), and the preview lists the related posts.

It reads the post's relationships through the existing v2 route, like the other abilities, so validation and permissions come from the route. Errors use rest_relationship_not_found for an unknown rel_key and rest_invalid_param for a post type the relationship doesn't relate to. Post-to-user relationships aren't supported because the Query Loop lists posts.

The other ability descriptions now name this one.

Known gap

The markup is meant for the source post's own content and bakes in related_to_post. It doesn't cover templates. The editor extension already has the same limitation: in the Site Editor, currentPostId is the template ID, so "related to the current post" doesn't resolve. Fixing that needs a render-time "current post" mode in the extension and is out of scope here.

How to test

  1. On University 1 from the example data, run the ability with rel_key: university_course_courses and post_type: course.
  2. Put the returned markup in University 1's content. The editor shows a valid Query Loop listing Course 1 and Course 2, and the post isn't marked dirty.
  3. npm run test:php passes. AbilitiesTest renders the markup with do_blocks() and checks that only the related post appears.

Changelog Entry

Added - Read-only ability content-connect/get-related-query-block that returns Query Loop markup listing a post's related posts.

@fabiankaegy

Copy link
Copy Markdown
Member Author

I'm still not sure about this one. But wanted to get everyones thoughts

dependabot Bot and others added 22 commits October 20, 2026 18:26
Bumps the npm_and_yarn group with 1 update in the / directory: [simple-git](https://github.com/steveukx/git-js/tree/HEAD/simple-git).


Updates `simple-git` from 3.36.0 to 4.0.2
- [Release notes](https://github.com/steveukx/git-js/releases)
- [Changelog](https://github.com/steveukx/git-js/blob/main/simple-git/CHANGELOG.md)
- [Commits](https://github.com/steveukx/git-js/commits/simple-git@4.0.2/simple-git)

---
updated-dependencies:
- dependency-name: simple-git
  dependency-version: 4.0.2
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
…n-9546ba3e65

Bump simple-git from 3.36.0 to 4.0.2 in the npm_and_yarn group across 1 directory
Bumps the npm_and_yarn group with 1 update in the / directory: [follow-redirects](https://github.com/follow-redirects/follow-redirects).


Updates `follow-redirects` from 1.16.0 to 1.16.1
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.16.0...v1.16.1)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.1
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
…n-5a3dbbc827

Bump follow-redirects from 1.16.0 to 1.16.1 in the npm_and_yarn group across 1 directory
Bumps the npm_and_yarn group with 1 update in the / directory: [launch-editor](https://github.com/vitejs/launch-editor).


Updates `launch-editor` from 2.14.1 to 2.14.2
- [Commits](vitejs/launch-editor@v2.14.1...v2.14.2)

---
updated-dependencies:
- dependency-name: launch-editor
  dependency-version: 2.14.2
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
…n-99967b6463

Bump launch-editor from 2.14.1 to 2.14.2 in the npm_and_yarn group across 1 directory
Add the content-connect:* links only for users who can edit the post,
since the endpoints they point to require edit_post. Apply the
relationshipQuery and orderByRelationship params on wp/v2 post endpoints
only for users who can edit posts of the queried type.

Add the tenup_content_connect_add_rest_links and
tenup_content_connect_rest_relationship_query_allowed filters to change
either default.
Bumps the npm_and_yarn group with 1 update in the / directory: [fast-uri](https://github.com/fastify/fast-uri).


Updates `fast-uri` from 3.1.8 to 3.1.9
- [Release notes](https://github.com/fastify/fast-uri/releases)
- [Commits](fastify/fast-uri@v3.1.8...v3.1.9)

---
updated-dependencies:
- dependency-name: fast-uri
  dependency-version: 3.1.9
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
…n-571e357d2d

Bump fast-uri from 3.1.8 to 3.1.9 in the npm_and_yarn group across 1 directory
…dates

Bumps the npm_and_yarn group with 4 updates in the / directory: [body-parser](https://github.com/expressjs/body-parser), [postcss-selector-parser](https://github.com/postcss/postcss-selector-parser), [serialize-javascript](https://github.com/yahoo/serialize-javascript) and [seroval](https://github.com/lxsmnsyc/seroval).


Updates `body-parser` from 1.20.6 to 1.20.9
- [Release notes](https://github.com/expressjs/body-parser/releases)
- [Changelog](https://github.com/expressjs/body-parser/blob/1.20.9/HISTORY.md)
- [Commits](expressjs/body-parser@1.20.6...1.20.9)

Updates `postcss-selector-parser` from 6.1.4 to 6.1.6
- [Release notes](https://github.com/postcss/postcss-selector-parser/releases)
- [Changelog](https://github.com/postcss/postcss-selector-parser/blob/6.1.6/CHANGELOG.md)
- [Commits](postcss/postcss-selector-parser@6.1.4...6.1.6)

Updates `serialize-javascript` from 7.1.2 to 7.1.4
- [Release notes](https://github.com/yahoo/serialize-javascript/releases)
- [Commits](yahoo/serialize-javascript@v7.1.2...v7.1.4)

Updates `seroval` from 1.6.2 to 1.8.0
- [Release notes](https://github.com/lxsmnsyc/seroval/releases)
- [Commits](https://github.com/lxsmnsyc/seroval/compare/seroval@1.6.2...seroval@1.8.0)

---
updated-dependencies:
- dependency-name: body-parser
  dependency-version: 1.20.9
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: postcss-selector-parser
  dependency-version: 6.1.6
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: serialize-javascript
  dependency-version: 7.1.4
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: seroval
  dependency-version: 1.8.0
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
Keep relationship data out of anonymous REST responses
…n-a206a802a7

build(deps): bump the npm_and_yarn group across 1 directory with 4 updates
Bumps the npm_and_yarn group with 1 update in the / directory: [follow-redirects](https://github.com/follow-redirects/follow-redirects).


Updates `follow-redirects` from 1.16.1 to 1.16.3
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.16.1...v1.16.3)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-version: 1.16.3
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
…n-ac04d359fb

build(deps): bump follow-redirects from 1.16.1 to 1.16.3 in the npm_and_yarn group across 1 directory
- load related items in the editor store with post_status=any
- when replacing related items, keep the related posts the user cannot list, using the same query and readability restriction as the related list, and leave them out of the response
- share the related posts query args, readability restriction, and filtered query between the list and the replace paths
- rebuild the editor bundles
getRelationships and getRelatedEntities return shared empty values when the store has no data, so useSelect gets the same reference on each call. The editor bundles are rebuilt.
Bumps the npm_and_yarn group with 1 update in the / directory: [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser).


Updates `fast-xml-parser` from 5.11.2 to 5.12.1
- [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases)
- [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md)
- [Commits](NaturalIntelligence/fast-xml-parser@v5.11.2...v5.12.1)

---
updated-dependencies:
- dependency-name: fast-xml-parser
  dependency-version: 5.12.1
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Category description names Query Loop filter attributes (showRelated,
relationshipKey, sourcePost), needs inherit false, post-to-post only.
get-post-relationships and get-related-items point to it. rel_name
schema moves to shared helper: pairs with related_to_post or
related_to_user, not unique across post types, use rel_key.

Co-authored-by: Sérgio Santos <me@s3rgiosan.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
content-connect/get-related-query-block builds the core/query markup
for a post's related posts through one post-to-post relationship. The
attributes match what the block editor extension stores, so the block
opens unchanged in the editor and renders through the existing query
loop integration. The other ability descriptions point to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@s3rgiosan
s3rgiosan force-pushed the feature/abilities-related-query-block branch from 6ad1f99 to 3e2017b Compare December 3, 2026 13:43
Copilot AI balanced review requested due to automatic review settings December 3, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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.

3 participants