PHPackages                             rickwest/laravel-wordpress-api - 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. rickwest/laravel-wordpress-api

ActiveLibrary[API Development](/categories/api)

rickwest/laravel-wordpress-api
==============================

A Laravel read-only client for the WordPress REST API (v2)

v1.3.0(9mo ago)3712.5k—0%14[4 PRs](https://github.com/rickwest/laravel-wordpress-api/pulls)1MITPHPPHP ^8.1|^8.2CI passing

Since Jul 28Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/rickwest/laravel-wordpress-api)[ Packagist](https://packagist.org/packages/rickwest/laravel-wordpress-api)[ Docs](https://github.com/rickwest/laravel-wordpress-api)[ RSS](/packages/rickwest-laravel-wordpress-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (12)Versions (12)Used By (1)

[![](./art/social-image.png)](./art/social-image.png)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2928f696df5e5bdbc1750fe15a6bf43ca4792fbd3e01d883172cf4f4eb4957a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269636b776573742f6c61726176656c2d776f726470726573732d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rickwest/laravel-wordpress-api)[![GitHub Tests Action Status](https://camo.githubusercontent.com/21f502421bb71c35090426a040806d95fd219e8918bef0bf4ec1051b58f00891/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7269636b776573742f6c61726176656c2d776f726470726573732d6170692f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/rickwest/laravel-wordpress-api/actions/workflows/run-tests.yml)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0ac19e5e9bce485d66034c5141805c729b4607b1f3aeaa89fb93fe715a89f6f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7269636b776573742f6c61726176656c2d776f726470726573732d6170692f7068702d63732d66697865722e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65)](https://github.com/rickwest/laravel-wordpress-api/actions/workflows/php-cs-fixer.yml)[![GitHub Tests Action Status](https://camo.githubusercontent.com/109d18221ec48749170de2a66ab131cf376d7caf93199bc82550e54997eace66/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7269636b776573742f6c61726176656c2d776f726470726573732d6170692f7068707374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d737461746963253230616e616c79736973)](https://github.com/rickwest/laravel-wordpress-api/actions/workflows/php-cs-fixer.yml)[![Total Downloads](https://camo.githubusercontent.com/827d11b96a79e4d26b7fa466ec6e7b6c61a98a75e52d346867074758c71b6263/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7269636b776573742f6c61726176656c2d776f726470726573732d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rickwest/laravel-wordpress-api)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

An unambitious read-only client for the WordPress REST API (v2). This package is the by-product of a side project, having found that I wanted a more expressive, fluent, Laravel-esque way of querying the WordPress API.

```
// Without the package 👎
Http::get('https://example.com/wp-json/wp/v2/posts', [
    'search' => 'potatoes',
    '_embed' => 1,
    'orderby' => 'date',
    'order' => 'desc'
    '_fields' => 'title',
]);

// Using the package 👌
WordPress::posts()
    ->search('potatoes')
    ->embed()
    ->latest()
    ->get('title');
```

As well as the fluent query builder, you also benefit from a nicely formatted response, including pagination information.

```
// Without the package 👎
$response = Http::get('https://example.com/wp-json/wp/v2/posts');
$data = $response->json();
$pages = $response->header('X-WP-TotalPages');
$total = $response->header('X-WP-Total');

// Using the package 👌
$posts = WordPress::posts()->get();

// $posts
[
    'data' => [...],
    'meta' => [
        'pages' => 1,
        'total' => 10,
    ],
],
```

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

[](#installation)

You can install the package via composer:

```
composer require rickwest/laravel-wordpress-api
```

Then you need to add your WordPress url to your `.env` file:

```
WORDPRESS_URL=https://example.com
```

Usage
-----

[](#usage)

This package binds a singleton to the Laravel service container, so you can easily resolve the WordPress client directly from the container, or via dependency injection. Alternatively, the package also exposes both a Facade and a helper function should you prefer a shorter more expressive option.

Currently, the package has support for the following WordPress resources: *categories, comments, media, pages, posts, users*. Adding support for further resources is really easy, but these are the only ones that I need for now! For a list of all available resources please see . I'm happy to accept PR's for any additions.

```
// Resolve service directly from container and access the Posts API
app(WordPress::class)->posts();

// Resolve via Facade and access the Posts API
WordPress::posts();

// Resolve service via helper and access the Posts API
wordpress()->posts();

// Supported resources
WordPress::categories(); // Access the Categories API
WordPress::comments(); // Access the Comments API
WordPress::media(); // Access the Media API
WordPress::pages(); // Access the Pages API
WordPress::posts(); // Access the Posts API
WordPress::users(); // Access the Users API
Wordpress::tags(); // Access the Tags API
Wordpress::plugins(); // Access the Plugins API

// You can also access resources as properties
wordpress()->posts
```

### Retrieve a single resource

[](#retrieve-a-single-resource)

Call the `find` method on a resource class in order to get a single resource by ID:

```
WordPress::posts()->find(1);

// All WordPress resources share a handful of global parameters. https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/
// You can use the relevant fluent builder methods to add these to your query
WordPress::posts()->embed()->fields('title')->find(1);

// Some resources also accept a limited number of resource specific parameters. These can be passed as a second argument to the find method
WordPress::posts()->find(1, ['password' => 'pa55w0rd']);
```

### Retrieve a collection of resources

[](#retrieve-a-collection-of-resources)

Call the `get` method on a resource to retrieve a collection of resources. The response you receive can be controlled and filtered using various parameters, . This package provides some fluent builder methods in order to easily and expressively build your desired query. Collection responses are then nicely formatted and include useful pagination information.

```
WordPress::posts()->get();

// All WordPress resources share a handful of global parameters, https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/,
// along with a number of filtering, ordering and pagination options. You can use the relevant fluent builder methods to build your query.
WordPress::posts()
    ->embed(array|string $relations) // Embed linked resources into response. Reduces need for extra HTTP requests for related resources
    ->fields(array|string $fields) // Specify a subset fields to return in a response
    ->with(array|string $fields) // Alias for fields method above
    ->page(int $page) // Current page of the collection
    ->perPage(int $perPage) // Maximum number of items to be returned in result set
    ->search(string $term) // Limit results to those matching a string
    ->offset(int $offset) // Offset the result set by a specific number of items
    ->exlclude(int|array $ids) // Ensure result set excludes specific IDs
    ->inlude(int|array $ids) // Limit result set to specific IDs
    ->orderBy(string $field, string $direction) // Sort collection by object attribute, either ascending or descending

    // Resources with authors
    ->author() // Limit result set to resources assigned to specific authors
    ->authorExclude() // Ensure result set excludes resources assigned to specific authors

    // Resources with dates
    ->after(Carbon $after) // Limit response to resources published after a given ISO8601 compliant date
    ->before(Carbon $before) // Limit response to resources published before a given ISO8601 compliant date
    ->latest() // Order by date, descending
    ->oldest() // Order by date, ascending

    // Resources with slugs
    ->slug(string $slug)

    // When a utility doesn't exist for the parameter
    ->parameter(string $key, mixed $value) // Add a custom parameter to the query

    // Send it!
    ->get();

// Conditionally adding parameters
WordPress::posts()
    ->when($onlyIncludeTitle, function($query) {
        $query->fields('title');
    })
    ->get();
```

### Creating, updating and deleting resources

[](#creating-updating-and-deleting-resources)

Whilst this package is primarily intended for reading data from the WordPress API, it is possible to perform write operations using the `send` method on a resource class.

```
WordPress::posts()->send(string $method, int $id, array $options);

// For example, updating a post might look like...
WordPress::posts()->send('POST', 1, [
    'json' => ['title' => 'My New Title'],
]);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Rick West](https://github.com/rickwest)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance68

Regular maintenance activity

Popularity39

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 53.5% 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 ~221 days

Recently: every ~277 days

Total

6

Last Release

282d ago

Major Versions

v0.1.0 → v1.0.02022-07-28

v0.1.1 → v1.1.02023-03-31

PHP version history (2 changes)v0.1.0PHP ^8.1

v1.3.0PHP ^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a8d59a529aae658b083a9f6977dc82105d12463958e5a0ecdd008c73d3ac017?d=identicon)[rickwest](/maintainers/rickwest)

---

Top Contributors

[![rickwest](https://avatars.githubusercontent.com/u/24735291?v=4)](https://github.com/rickwest "rickwest (38 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (17 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (11 commits)")[![DevProsanta](https://avatars.githubusercontent.com/u/96200939?v=4)](https://github.com/DevProsanta "DevProsanta (3 commits)")[![rosswintle](https://avatars.githubusercontent.com/u/1532368?v=4)](https://github.com/rosswintle "rosswintle (1 commits)")[![talss89](https://avatars.githubusercontent.com/u/1142987?v=4)](https://github.com/talss89 "talss89 (1 commits)")

---

Tags

api-clientlaravelphpwordpressapilaravelwordpress

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/rickwest-laravel-wordpress-api/health.svg)

```
[![Health](https://phpackages.com/badges/rickwest-laravel-wordpress-api/health.svg)](https://phpackages.com/packages/rickwest-laravel-wordpress-api)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k7.8M57](/packages/dedoc-scramble)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[stechstudio/laravel-hubspot

A Laravel SDK for the HubSpot CRM Api

2971.0k](/packages/stechstudio-laravel-hubspot)[njoguamos/laravel-plausible

A laravel package for interacting with plausible analytics api.

208.8k](/packages/njoguamos-laravel-plausible)[tapp/filament-webhook-client

Add a Filament resource and a policy for Spatie Webhook client

1120.2k](/packages/tapp-filament-webhook-client)

PHPackages © 2026

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