Skip to content

Try 2: Add get and post/pages abilities.#10867

Open
jorgefilipecosta wants to merge 8 commits intoWordPress:trunkfrom
jorgefilipecosta:add/get-post-abilities
Open

Try 2: Add get and post/pages abilities.#10867
jorgefilipecosta wants to merge 8 commits intoWordPress:trunkfrom
jorgefilipecosta:add/get-post-abilities

Conversation

@jorgefilipecosta
Copy link
Member

Part of: WordPress/ai#40

Alternative to #10665, trying to implement what was discussed with
@JasonTheAdams and @justlevine.

This PR adds get abilities for post types via the Abilities API, enabling AI agents to retrieve posts and pages through core/post-type/{slug}/get. It Introduce a show_in_abilities option on register_post_type() to control which post types expose abilities, enabled by default for post and page for now (if we agree in this approach we will expand to menus, media etc)-
Support single-post retrieval by ID and multi-post querying with filters for status, author, search, taxonomy, meta, date, comment status, ping status and more.

I think the biggest decision we need to do is the naming of the ability. I went for core/post-type/{post-type-slug}/get where post-type-slug is the post type identifier (post, page etc). We could discuss other naming possibilities.

Test plan

Retrieve a single post by ID with meta and taxonomies (use a valid id):

await wp.apiFetch({
  path: wp.url.addQueryArgs(
    '/wp-abilities/v1/abilities/core/post-type/post/get/run',
    { input: { id: 334, include: { meta: true, taxonomies: true } } }
  )
});

Query posts filtered by meta key existence:

await wp.apiFetch({
  path: wp.url.addQueryArgs(
    '/wp-abilities/v1/abilities/core/post-type/post/get/run',
    {
      input: {
        include: { meta: true },
        query: {
          meta: {
            queries: [{ key: 'footnotes', compare: 'EXISTS' }]
          }
        }
      }
    }
  )
});

Nested meta query with AND/OR relations:

await wp.apiFetch({
  path: wp.url.addQueryArgs(
    '/wp-abilities/v1/abilities/core/post-type/post/get/run',
    {
      input: {
        include: { meta: true },
        query: {
          meta: {
            relation: 'AND',
            queries: [
              { key: 'a', compare: '=', value: '23' },
              {
                relation: 'OR',
                queries: [
                  { key: 'b', compare: '=', value: '1' },
                  { key: 'c', compare: '=', value: '1' }
                ]
              }
            ]
          }
        }
      }
    }
  )
});

Nested taxonomy query with AND/OR relations:

await wp.apiFetch({
  path: wp.url.addQueryArgs(
    '/wp-abilities/v1/abilities/core/post-type/post/get/run',
    {
      input: {
        include: { meta: true },
        query: {
          tax: {
            relation: 'AND',
            queries: [
              { taxonomy: 'post_tag', field: 'slug', terms: ['t-23'] },
              {
                relation: 'OR',
                queries: [
                  { taxonomy: 'post_tag', field: 'slug', terms: ['c-1'] },
                  { taxonomy: 'post_tag', field: 'slug', terms: ['b-1'] }
                ]
              }
            ]
          }
        }
      }
    }
  )
});

Retrieve most recent pages:

await wp.apiFetch({
  path: wp.url.addQueryArgs(
    '/wp-abilities/v1/abilities/core/post-type/post/get/run',
    { input: { id: 334, include: { meta: true, taxonomies: true } } }
  )
});

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

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 props-bot label.

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

Props jorgefilipecosta, mukesh27.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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 changed the title Add/get post abilities Try 2: Add get and post/pages abilities. Feb 4, 2026
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Quick review

* @return WP_Ability|null The registered ability instance on success, null on failure.
*/
public function register( string $name, array $args ): ?WP_Ability {
if ( ! preg_match( '/^[a-z0-9-]+\/[a-z0-9-]+$/', $name ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is extracted in a different PR, and is a temporary just for testing.

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.

2 participants