PHPackages                             dbout/wp-orm - 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. [Database &amp; ORM](/categories/database)
4. /
5. dbout/wp-orm

ActivePackage[Database &amp; ORM](/categories/database)

dbout/wp-orm
============

WordPress ORM with Eloquent.

v13.0.1(1mo ago)12910.3k↓58.1%11[2 issues](https://github.com/dimitriBouteille/wp-orm/issues)[5 PRs](https://github.com/dimitriBouteille/wp-orm/pulls)1MITPHPPHP &gt;=8.3CI passing

Since Aug 13Pushed 3w ago3 watchersCompare

[ Source](https://github.com/dimitriBouteille/wp-orm)[ Packagist](https://packagist.org/packages/dbout/wp-orm)[ Docs](https://github.com/dimitriBouteille/wp-orm)[ RSS](/packages/dbout-wp-orm/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (31)Versions (54)Used By (1)

WordPress ORM with Eloquent
===========================

[](#wordpress-orm-with-eloquent)

[![GitHub Release](https://camo.githubusercontent.com/4eae96476be306d8f2db8353cfa1850b14654b390361e95621c07e453648c20c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f64696d69747269426f757465696c6c652f77702d6f726d)](https://github.com/dimitriBouteille/wp-orm/releases)[![Tests](https://camo.githubusercontent.com/dfeada672449b9d81899e3e44277fb0b0cdfae76efb354726db7c3f944e4bf6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64696d69747269426f757465696c6c652f77702d6f726d2f74657374732e796d6c3f6c6162656c3d7465737473)](https://github.com/dimitriBouteille/wp-orm/actions/workflows/tests.yml)[![Packagist Downloads](https://camo.githubusercontent.com/cb92a5567e5ae0dae5007ed7e638d98c529ebfacbf4ca4735b59c49341cd0de6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64626f75742f77702d6f726d3f636f6c6f723d79656c6c6f77)](https://packagist.org/packages/dbout/wp-orm)[![Eloquent version](https://camo.githubusercontent.com/ea7394ef66a3840cdd23d3e7092152fe963c93757064340143020c9355a0738b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f64626f75742f77702d6f726d2f696c6c756d696e61746525324664617461626173653f636f6c6f723d6f72616e6765)](https://github.com/dimitriBouteille/wp-orm/blob/main/composer.json)[![Coverage Status](https://camo.githubusercontent.com/751715513dd608ecf606911ecacc7e78a41be412aca73d1cef16a3563729f2f8/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f64696d69747269426f757465696c6c652f77702d6f726d2f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/dimitriBouteille/wp-orm)

WordPress ORM with Eloquent is a small library that adds a basic ORM into WordPress, which is easily extendable and includes models for core WordPress models such as posts, post metas, users, comments and more. The ORM is based on [Eloquent ORM](https://laravel.com/docs/eloquent) and uses the WordPress connection (`wpdb` class).

Tip

To simplify the integration of this library, we recommend using WordPress with one of the following tools: [Bedrock](https://roots.io/bedrock/), [Themosis](https://framework.themosis.com/) or [Wordplate](https://github.com/wordplate/wordplate#readme).

Features
--------

[](#features)

- ✅ Support core WordPress models: `Comment`, `Option`, `Post`, `Term`, `TermTaxonomy`, `TermRelationship`, `User`, `PostMeta` and `UserMeta`
- ✅ Support core WordPress post types: `Article`, `Attachment` and `Page`
- ✅ Based on core WordPress database connection (`wpdb` class), no configuration required
- ✅ Custom functions to filter models with meta
- ✅ Meta casting (e.g. [Attribute Casting](https://laravel.com/docs/eloquent-mutators#attribute-casting))
- ❤️ Easy integration of a custom post and comment type
- ❤️ Easy model creation for projects with custom tables
- ❤️ All the features available in Eloquent are usable with this library

**Not yet developed but planned in a future version:**

- 🗓️ [Create migration tool with Eloquent](https://github.com/dimitriBouteille/wp-orm/issues/28)
- 🗓️ Multisite support (network-shared tables and `switch_blog()` handling)

Documentation
-------------

[](#documentation)

This documentation only covers the specific points of this library, if you want to know more about Eloquent, the easiest is to look at [the documentation of Eloquent](https://laravel.com/docs/eloquent).

You can find all the documentation in [the wiki](https://github.com/dimitriBouteille/wp-orm/wiki).

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

[](#installation)

**Requirements**

This package targets a stricter runtime than [WordPress itself](https://wordpress.org/about/requirements/):

- PHP &gt;= 8.3
- WordPress &gt;= 6.3
- [Composer](https://getcomposer.org/)

**Installation**

You can use [Composer](https://getcomposer.org/). Follow the [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.

```
composer require dbout/wp-orm
```

In your `wp-config.php` make sure you include the autoloader:

```
require __DIR__ . '/vendor/autoload.php';
```

🎉 You have nothing more to do, you can use the library now. No need to configure database accesses because the `wpdb` connection is used.

Quick start
-----------

[](#quick-start)

Once installed, every model is ready to use without any configuration. Here are the most common patterns:

**Retrieve a model**

```
use Dbout\WpOrm\Models\Post;
use Dbout\WpOrm\Models\User;

$post = Post::find(42);
$post = Post::findOneByName('hello-world');

$user = User::findOneByEmail('john@example.com');
```

**Query with the builder**

```
use Dbout\WpOrm\Enums\PostStatus;
use Dbout\WpOrm\Models\Post;

$publishedPosts = Post::query()
    ->whereStatus(PostStatus::Publish)
    ->whereTypes('post', 'page')
    ->orderBy(Post::DATE, 'desc')
    ->limit(10)
    ->get();
```

**Create or update a model**

```
use Dbout\WpOrm\Models\Post;

$post = new Post();
$post->setPostTitle('Hello world');
$post->setPostName('hello-world');
$post->setPostType('post');
$post->save();

$post->setPostTitle('Hello, again');
$post->save();
```

**Work with metas**

```
$post->setMeta('color', 'blue');
$value = $post->getMetaValue('color');     // 'blue'
$post->hasMeta('color');                    // true
$post->deleteMeta('color');

// Filter posts by meta value
Post::query()
    ->addMetaToFilter('color', 'blue')
    ->addMetaToSelect('size')
    ->get();
```

**Use relations**

```
$post = Post::find(42);

$author = $post->author;        // BelongsTo User
$comments = $post->comments;    // HasMany Comment
$parent = $post->parent;        // BelongsTo Post (self)
```

For everything else (eager loading, scopes, transactions, casts…), see [the Eloquent documentation](https://laravel.com/docs/eloquent) — every Eloquent feature works out of the box.

Security notes
--------------

[](#security-notes)

Warning

**Mass assignment is wide open by default.**Every model inherits `protected $guarded = []`, which means **every column is mass-assignable**. A call like `User::create($_POST)` would let a caller set sensitive fields such as `user_pass`. When you accept user input, always pre-validate it or override `$fillable` / `$guarded` on the model:

```
class SafeUser extends \Dbout\WpOrm\Models\User
{
    protected $fillable = [
        self::LOGIN,
        self::EMAIL,
        self::DISPLAY_NAME,
    ];
}
```

Warning

**Multisite is not supported in this release.**The library does not handle network-shared tables or `switch_blog()`. After a `switch_blog()` call, the connection prefix is not refreshed and models targeting shared tables (`User`, `UserMeta`) may produce incorrect queries on subsites. Multisite support is planned for a future release — track [the milestone](https://github.com/dimitriBouteille/wp-orm/issues) for progress.

Testing
-------

[](#testing)

🐞 This project includes two types of tests:

- **Unit tests** - Isolated tests without WordPress dependencies
- **WordPress tests** - Integration tests with WordPress core (uses [`wp-phpunit/wp-phpunit`](https://github.com/wp-phpunit/wp-phpunit))

Both suites run on PHPUnit 12.

**Running tests:**

```
# Unit tests
composer run test:unit

# WordPress tests (requires Docker)
./run-wp-tests.sh

# With coverage
./run-wp-tests.sh --coverage
```

**Local setup:**

WordPress tests require Docker and Subversion. The `run-wp-tests.sh` script automatically sets up a MySQL container and installs WordPress test environment. WordPress files are cached in `var/testings/` for faster subsequent runs.

See [TESTING.md](TESTING.md) for detailed setup instructions and troubleshooting.

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

[](#contributing)

💕 🦄 We encourage you to contribute to this repository, so everyone can benefit from new features, bug fixes, and any other improvements. Have a look at our [contributing guidelines](CONTRIBUTING.md) to find out how to raise a pull request.

###  Health Score

64

—

FairBetter than 99% of packages

Maintenance94

Actively maintained with recent releases

Popularity40

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.2% 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 ~68 days

Recently: every ~4 days

Total

32

Last Release

40d ago

Major Versions

v1.0.0 → v2.0.02023-09-25

v2.0.0 → 3.0.0-beta.62024-01-29

3.3.0 → 4.0.0-alpha.02024-10-09

v4.3.1 → v5.0.0-alpha.02025-12-07

5.x-dev → v13.0.02026-05-09

PHP version history (5 changes)v1.0.0PHP &gt;=7.2

v2.0.0PHP ^7.4|^8.0

3.0.0-beta.6PHP &gt;=8.1

4.0.0-alpha.0PHP &gt;=8.2

v5.0.0-alpha.1PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3e5be30a5fa3cbb2c1ec8b80f81d752a6700dbca5a9ab419a508293e68fbde7c?d=identicon)[dimitriBouteille](/maintainers/dimitriBouteille)

---

Top Contributors

[![dimitriBouteille](https://avatars.githubusercontent.com/u/34821762?v=4)](https://github.com/dimitriBouteille "dimitriBouteille (602 commits)")[![rafaucau](https://avatars.githubusercontent.com/u/25438601?v=4)](https://github.com/rafaucau "rafaucau (14 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (12 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (11 commits)")

---

Tags

databaseeloquenteloquent-databaseeloquent-ormmigration-toolmysqlormwordpresswordpress-developmentwordpress-ormwordpress-starterwordpressmigrationdatabaseormsqleloquentdbwp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dbout-wp-orm/health.svg)

```
[![Health](https://phpackages.com/badges/dbout-wp-orm/health.svg)](https://phpackages.com/packages/dbout-wp-orm)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[aimeos/laravel-nestedset

Nested Set Model for Laravel

3714.4k6](/packages/aimeos-laravel-nestedset)

PHPackages © 2026

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