PHPackages                             developvi/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. developvi/wp-orm

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

developvi/wp-orm
================

1.0.0(1y ago)13PHP

Since Feb 1Pushed 1y agoCompare

[ Source](https://github.com/developvi/wp-orm)[ Packagist](https://packagist.org/packages/developvi/wp-orm)[ RSS](/packages/developvi-wp-orm/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

WPModel Class Documentation
===========================

[](#wpmodel-class-documentation)

Introduction
------------

[](#introduction)

The `WPModel` class is a custom database model class designed for WordPress using the `$wpdb` object for database interactions. It provides a fluent interface for building and executing SQL queries.

Properties
----------

[](#properties)

- `protected $table;` - The table name with prefix.
- `protected $primaryKey = 'id';` - The primary key of the table.
- `protected $wpdb;` - WordPress database object.
- `protected $selectClause = '*';` - Default select clause.
- `protected $whereClauses = [];` - Array to store WHERE clauses.
- `protected $joinClauses = [];` - Array to store JOIN clauses.
- `protected $orderByClause = '';` - ORDER BY clause.
- `protected $groupByClause = '';` - GROUP BY clause.
- `protected $havingClause = '';` - HAVING clause.
- `protected $limitClause = '';` - LIMIT clause.
- `protected $offsetClause = '';` - OFFSET clause.
- `protected $with = [];` - Relations to eager load.

Methods
-------

[](#methods)

### \_\_construct()

[](#__construct)

Initializes the `$wpdb` object and sets the table name.

### select($columns = \['\*'\])

[](#selectcolumns--)

Sets the columns to be selected in the query.

```
$model->select(['name', 'email']);

```

### with($relations)

[](#withrelations)

Eager loads relationships.

```
$model->with('posts');

```

### where($column, $operator = '=', $value = null)

[](#wherecolumn-operator---value--null)

Adds a WHERE clause to the query.

```
$model->where('status', '=', 'active');

```

### orWhere($column, $operator = '=', $value = null)

[](#orwherecolumn-operator---value--null)

Adds an OR WHERE clause to the query.

### whereAny(array $columns, $operator = '=', $value = null)

[](#whereanyarray-columns-operator---value--null)

Adds WHERE clauses for any of the specified columns.

### whereAll(array $columns, $operator = '=', $value = null)

[](#whereallarray-columns-operator---value--null)

Adds WHERE clauses for all of the specified columns.

### join($table, $first, $operator, $second)

[](#jointable-first-operator-second)

Adds an INNER JOIN clause to the query.

### leftJoin($table, $first, $operator, $second)

[](#leftjointable-first-operator-second)

Adds a LEFT JOIN clause to the query.

### rightJoin($table, $first, $operator, $second)

[](#rightjointable-first-operator-second)

Adds a RIGHT JOIN clause to the query.

### orderBy($column, $direction = 'ASC')

[](#orderbycolumn-direction--asc)

Sets the ORDER BY clause.

### groupBy($column)

[](#groupbycolumn)

Sets the GROUP BY clause.

### having($column, $operator = '=', $value = null)

[](#havingcolumn-operator---value--null)

Sets the HAVING clause.

### limit($limit)

[](#limitlimit)

Sets the LIMIT clause.

### offset($offset)

[](#offsetoffset)

Sets the OFFSET clause.

### get($id)

[](#getid)

Retrieves a single record by ID.

### getAll()

[](#getall)

Retrieves all records based on the current query.

### create($data)

[](#createdata)

Inserts a new record into the database.

### update($id, $data)

[](#updateid-data)

Updates a record with the given ID.

### delete($id)

[](#deleteid)

Deletes a record with the given ID.

### count()

[](#count)

Returns the count of records based on the current query.

### first()

[](#first)

Retrieves the first record based on the current query.

### exists()

[](#exists)

Checks if any records exist based on the current query.

### avg($column)

[](#avgcolumn)

Returns the average value of a column.

### sum($column)

[](#sumcolumn)

Returns the sum of a column.

### max($column)

[](#maxcolumn)

Returns the maximum value of a column.

### min($column)

[](#mincolumn)

Returns the minimum value of a column.

### pluck($column)

[](#pluckcolumn)

Returns an array of values for a single column.

### distinct()

[](#distinct)

Selects distinct values in the query.

### updateOrInsert($attributes, $values = \[\])

[](#updateorinsertattributes-values--)

Updates an existing record or inserts a new one.

### hasOne($related, $foreignKey, $localKey)

[](#hasonerelated-foreignkey-localkey)

Defines a one-to-one relationship.

### hasMany($related, $foreignKey, $localKey)

[](#hasmanyrelated-foreignkey-localkey)

Defines a one-to-many relationship.

### belongsToMany($related, $pivotTable, $foreignPivotKey, $relatedPivotKey, $localKey, $relatedKey)

[](#belongstomanyrelated-pivottable-foreignpivotkey-relatedpivotkey-localkey-relatedkey)

Defines a many-to-many relationship.

### beginTransaction()

[](#begintransaction)

Starts a database transaction.

### commit()

[](#commit)

Commits the current transaction.

### rollback()

[](#rollback)

Rolls back the current transaction.

Example Usage
-------------

[](#example-usage)

```
 class Post extends WPModel
  {
     protected $table = 'posts';
     protected $primaryKey = 'ID';
  }
  $post = new Post();
  $post->first();
```

```
class Post extends WPModel
{
   protected $table = 'posts';
   protected $primaryKey = 'ID';

   public function postMeta()
   {
       return $this->hasOne(PostMeta::class, 'post_id', $this->primaryKey);
   }

}
class PostMeta extends WPModel
{
   protected $table = 'postmeta';
   protected $primaryKey = 'post_id';
}
  $post = new Post();
  $post->with('postMeta')->first();
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

518d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21009117?v=4)[eslam el sherif](/maintainers/eslam-dev)[@eslam-dev](https://github.com/eslam-dev)

---

Top Contributors

[![eslam-dev](https://avatars.githubusercontent.com/u/21009117?v=4)](https://github.com/eslam-dev "eslam-dev (3 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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