PHPackages                             rjjakes/wordpress-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. rjjakes/wordpress-orm

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

rjjakes/wordpress-orm
=====================

WORM. Doctrine style ORM for Wordpress.

0.1.0(3y ago)4995612[6 issues](https://github.com/rjjakes/wordpress-orm/issues)[1 PRs](https://github.com/rjjakes/wordpress-orm/pulls)MITPHPPHP &gt;=5.5

Since Jul 14Pushed 3y ago3 watchersCompare

[ Source](https://github.com/rjjakes/wordpress-orm)[ Packagist](https://packagist.org/packages/rjjakes/wordpress-orm)[ Docs](https://github.com/rjjakes/wordpress-orm)[ RSS](/packages/rjjakes-wordpress-orm/feed)WikiDiscussions master Synced 1w ago

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

WORM (Wordpress ORM)
====================

[](#worm-wordpress-orm)

*Under active development*

A lightweight, Doctrine style ORM for Wordpress 4.8+. Requires PHP 5.5+

This library borrows a lot of concepts from Doctrine for Symfony including the mapper, entity manager, repositories, one-to-many entity relationships, lazy-loading of related entities and a query builder.

It acts as a layer sitting on top of the internal Wordpress `$wpdb` class.

All queries are run through the internal Wordpress `$wpdb->prepare()` function to protect against SQL injection attacks.

Why?
----

[](#why)

I came to Wordpress from a Symfony development background. I wanted to work with objects instead of manually writing SQL queries. I looked around for a good ORM and was unable to find anything that fulfilled my requirements.

Getting Doctrine to work with Wordpress was complex and seemed like overkill as it's a very heavy weight library.

There's also:  which is really good, but is more of a query builder for existing Wordpress tables.

Version history
---------------

[](#version-history)

master branch = active development

0.1.0 tag = previous master. The version most people would be using circa last 2022.

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

[](#installation)

```
composer require rjjakes/wordpress-orm

```

Usage
-----

[](#usage)

### Create a model

[](#create-a-model)

To use the ORM, first create a class that extends the ORM base model and add a number of properties as protected variables. The property names must exactly match the desired SQL column names (there is no name mapping).

Note that a property of `$id` is added to the model when you do `extends BaseModel` so you do not need to add that.

Example:

```
