PHPackages                             the-under-scorer/wp-eloquent - 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. the-under-scorer/wp-eloquent

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

the-under-scorer/wp-eloquent
============================

Eloquent ORM for WordPress

1.5.2(6y ago)43471GPL-2.0-or-laterPHP

Since May 7Pushed 6y agoCompare

[ Source](https://github.com/TheUnderScorer/wp-eloquent)[ Packagist](https://packagist.org/packages/the-under-scorer/wp-eloquent)[ Docs](https://github.com/TheUnderScorer/wp-eloquent)[ RSS](/packages/the-under-scorer-wp-eloquent/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (24)Used By (1)

[![Build Status](https://camo.githubusercontent.com/37aeb1570d0fe1dbe55a23770d76a57725b0586519962493242312a6a03fa23b/68747470733a2f2f7472617669732d63692e636f6d2f546865556e64657253636f7265722f77702d656c6f7175656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/TheUnderScorer/wp-eloquent)

Eloquent Wrapper for WordPress
==============================

[](#eloquent-wrapper-for-wordpress)

This is a library package to use Laravel's [Eloquent ORM](http://laravel.com/docs/5.0/eloquent) with WordPress. It's an fork of original  library that seems to be abandoned.

Package Installation
--------------------

[](#package-installation)

To install this package run:

`$ composer require the-under-scorer/wp-eloquent`

Usage Example
=============

[](#usage-example)

Basic Usage
-----------

[](#basic-usage)

```
$db = \UnderScorer\ORM\Eloquent\Database::instance();

var_dump( $db->table('users')->find(1) );
var_dump( $db->select('SELECT * FROM wp_users WHERE id = ?', [1]) );
var_dump( $db->table('users')->where('user_login', 'john')->first() );

// OR with DB facade
use \UnderScorer\ORM\Eloquent\Facades\DB;

var_dump( DB::table('users')->find(1) );
var_dump( DB::select('SELECT * FROM wp_users WHERE id = ?', [1]) );
var_dump( DB::table('users')->where('user_login', 'john')->first() );
```

Creating Models For Custom Tables
---------------------------------

[](#creating-models-for-custom-tables)

You can use custom tables of the WordPress databases to create models:

```
	namespace whatever;

	class CustomTableModel extends \UnderScorer\ORM\Eloquent\Model {

		/**
		 * Name for table without prefix
		 *
		 * @var string
		 */
		protected $table = 'table_name';

		/**
		 * Columns that can be edited - IE not primary key or timestamps if being used
		 */
		protected $fillable = [
			'city',
			'state',
			'country'
		];

		/**
		 * Disable created_at and update_at columns, unless you have those.
		 */
		public $timestamps = false;

		/** Everything below this is best done in an abstract class that custom tables extend */

		/**
		 * Set primary key as ID, because WordPress
		 *
		 * @var string
		 */
		protected $primaryKey = 'ID';

		/**
		 * Make ID guarded -- without this ID doesn't save.
		 *
		 * @var string
		 */
		protected $guarded = [ 'ID' ];

		/**
		 * Overide parent method to make sure prefixing is correct.
		 *
		 * @return string
		 */
		public function getTable()
		{
			//In this example, it's set, but this is better in an abstract class
			if( isset( $this->table ) ){
				$prefix =  $this->getConnection()->db->prefix;
				return $prefix . $this->table;

			}

			return parent::getTable();
		}

	}

```

### Retrieving All Rows From A Table

[](#retrieving-all-rows-from-a-table)

```
$users = $db->table('users')->get();

foreach ($users as $user) {
    var_dump($user->display_name);
}
```

Here `users` is the table name **without prefix**. The prefix will be applied automatically.

### Other Examples

[](#other-examples)

- [Queries](http://laravel.com/docs/5.0/queries)
- [Eloquent ORM](http://laravel.com/docs/5.0/eloquent)

Writing a Model
---------------

[](#writing-a-model)

```
use \UnderScorer\ORM\Eloquent\Model as Model;

class Employee extends Model {

}

var_dump( Employee::all()->toArray() ); // gets all employees
var_dump( Employee::find(1) ); // find employee with ID 1
```

The class name `Employee` will be translated into `PREFIX_employees` table to run queries. But as usual, you can override the table name.

### In-built Models for WordPress

[](#in-built-models-for-wordpress)

- Post
- Comment
- Post Meta
- User
- User Meta
- Term
- TermTaxonomy

```
use UnderScorer\WP\Post;

var_dump( Post::all() ); //returns only posts with WordPress post_type "post"
```

#### Filter `Post` by `post_status` and `post_type`

[](#filter-post-by-post_status-and-post_type)

```
use UnderScorer\WP\Post;
var_dump(Post::type('page')->get()->toArray()); // get pages
var_dump(Post::status('publish')->get()->toArray()); // get posts with publish status
var_dump(Post::type('page')->status('publish')->get()->toArray()); // get pages with publish status
```

How it Works
------------

[](#how-it-works)

- Eloquent is mainly used here as the query builder
- [WPDB](http://codex.wordpress.org/Class_Reference/wpdb) is used to run queries built by Eloquent
- Hence, we have the benfit to use plugins like `debug-bar` or `query-monitor` to get SQL query reporting.
- It doesn't create any extra MySQL connection

Minimum Requirement
-------------------

[](#minimum-requirement)

- PHP 5.6.4+
- WordPress 4.0+

Author
------

[](#author)

[Tareq Hasan](https://tareq.co)[Przemysław Żydek](https://github.com/TheUnderScorer)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~42 days

Recently: every ~4 days

Total

22

Last Release

2408d ago

Major Versions

0.9 → 1.02018-04-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b333bcf3966a68acb81a28343f653ee6befa413ad25ae43312c2e4e50ecc161?d=identicon)[TheUnderScorer](/maintainers/TheUnderScorer)

---

Top Contributors

[![TheUnderScorer](https://avatars.githubusercontent.com/u/17906692?v=4)](https://github.com/TheUnderScorer "TheUnderScorer (41 commits)")[![tareq1988](https://avatars.githubusercontent.com/u/153669?v=4)](https://github.com/tareq1988 "tareq1988 (31 commits)")[![sohelamin](https://avatars.githubusercontent.com/u/1708683?v=4)](https://github.com/sohelamin "sohelamin (5 commits)")[![dsge](https://avatars.githubusercontent.com/u/5737250?v=4)](https://github.com/dsge "dsge (3 commits)")[![monkeymonk](https://avatars.githubusercontent.com/u/574338?v=4)](https://github.com/monkeymonk "monkeymonk (2 commits)")[![Shelob9](https://avatars.githubusercontent.com/u/1994311?v=4)](https://github.com/Shelob9 "Shelob9 (1 commits)")[![sabbir1991](https://avatars.githubusercontent.com/u/2692939?v=4)](https://github.com/sabbir1991 "sabbir1991 (1 commits)")[![sultann](https://avatars.githubusercontent.com/u/5239470?v=4)](https://github.com/sultann "sultann (1 commits)")[![mirzazeyrek](https://avatars.githubusercontent.com/u/6233650?v=4)](https://github.com/mirzazeyrek "mirzazeyrek (1 commits)")[![YevhenMikulenko](https://avatars.githubusercontent.com/u/5243125?v=4)](https://github.com/YevhenMikulenko "YevhenMikulenko (1 commits)")

---

Tags

pluginwordpressormsqleloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/the-under-scorer-wp-eloquent/health.svg)

```
[![Health](https://phpackages.com/badges/the-under-scorer-wp-eloquent/health.svg)](https://phpackages.com/packages/the-under-scorer-wp-eloquent)
```

###  Alternatives

[tareq1988/wp-eloquent

Eloquent ORM for WordPress

57254.7k](/packages/tareq1988-wp-eloquent)[dbout/wp-orm

WordPress ORM with Eloquent.

1279.6k1](/packages/dbout-wp-orm)

PHPackages © 2026

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