PHPackages                             humanmade/rest-api-search-by-id - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. humanmade/rest-api-search-by-id

ActiveWordpress-plugin[API Development](/categories/api)

humanmade/rest-api-search-by-id
===============================

WordPress plugin to support the include &amp; exclude parameters on the REST API /search endpoint.

v1.0.1(4y ago)213GPL-2.0+PHP

Since Oct 15Pushed 4y ago11 watchersCompare

[ Source](https://github.com/humanmade/rest-api-search-by-id)[ Packagist](https://packagist.org/packages/humanmade/rest-api-search-by-id)[ Docs](https://github.com/humanmade/rest-api-search-by-id)[ RSS](/packages/humanmade-rest-api-search-by-id/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

REST API Search by ID
=====================

[](#rest-api-search-by-id)

This plugin modifies the WordPress REST API [`/wp/v2/search` endpoint](https://developer.wordpress.org/rest-api/reference/search-results/) to support the `include` and `exclude` query parameters used in other collections.

In the default REST API you must know the post type for a resource in order to be able to query it, because API routes are broken out by resource type. However, in WordPress we have many functions which accept only an ID and return a matching post regardless of type. With this plugin active it is possible to query for a specific post object by ID, even if you do not know that record's post type:

```
/wp/v2/search?type=post&include=12345

```

useResourceById Hook
--------------------

[](#useresourcebyid-hook)

In addition to the API query parameter changes described above, when this plugin is active there is also a script with the handle `use-resource-by-id` enqueued while you are using the Block Editor. This script declares a [React hook](https://reactjs.org/docs/hooks-intro.html) which wraps the WordPress Block Editor's own [`getEntityRecord` selector](https://developer.wordpress.org/block-editor/reference-guides/data/data-core/#getentityrecord) to let you request a post resource without knowing its post type.

Usage:

```
// The hook is exposed as a browser global.
const { useResourceById } = window;

const MyComponent = () => {
	// Assuming the post object with ID 2501 is a 'customPostType', these two
	// hook calls will result in the exact same data:
	const result1 = useSelect( ( select ) => {
		return select( 'core' ).getEntityRecord( 'postType', 'post', 2501 );
	} );
	const result2 = useResourceById( 2501 );
};
```

This hook uses the search endpoint with the `include` parameter to determine the `subtype` of the requested record. That subtype is cached in memory once known, and the hook will thereafter return the results of a direct `getEntityRecord` call so that the resource is properly routed through the Block Editor data store.

Installation
------------

[](#installation)

Add this to your site with [Composer](https://getcomposer.org/) by running,

```
composer require humanmade/rest-api-search-by-id

```

The package specifies that this is a WordPress plugin, so depending on how you have your Composer installers configured, this should automatically end up in your plugins directory. You can of course also manually download a zipfile of a release and load it into your site by other means.

Caveats
-------

[](#caveats)

At present `include` and `exclude` as implemented in this plugin assume you are querying only for `post` objects. Support may be added later to permit searching across object types.

Release Process
---------------

[](#release-process)

To release a new version,

- bump the version numbers in `package.json` and `plugin.php` (both the plugin header and the version parameter in the `wp_enqueue_script` call)
- generate the minified file with `npm run build`
- commit the built code
- tag with the desired version number

For example,

```
# (Manually edit package.json and plugin.php to set version 1.2.3)
npm run build
git add js/use-resource-by-id.min.js
git commit -m 'Release v1.2.3'
git tag v1.2.3
git push origin main
git push origin --tags

```

License
-------

[](#license)

GPL v2 or later

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1721d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a498e093283b7b42aa63d5f75851cda7ec4c4e2137cb8482e02d3181b48eafa3?d=identicon)[kadamwhite](/maintainers/kadamwhite)

---

Top Contributors

[![kadamwhite](https://avatars.githubusercontent.com/u/442115?v=4)](https://github.com/kadamwhite "kadamwhite (10 commits)")

### Embed Badge

![Health badge](/badges/humanmade-rest-api-search-by-id/health.svg)

```
[![Health](https://phpackages.com/badges/humanmade-rest-api-search-by-id/health.svg)](https://phpackages.com/packages/humanmade-rest-api-search-by-id)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.5k10](/packages/helsingborg-stad-municipio)[october/rain

October Rain Library

1601.7M80](/packages/october-rain)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[sybrew/the-seo-framework

An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.

47884.4k](/packages/sybrew-the-seo-framework)[mediawiki/maps

Adds various mapping features to MediaWiki

84152.3k3](/packages/mediawiki-maps)[civicrm/civicrm-drupal-8

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

19251.4k3](/packages/civicrm-civicrm-drupal-8)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
