PHPackages                             matthiasweb/wpdb-batch - 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. matthiasweb/wpdb-batch

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

matthiasweb/wpdb-batch
======================

WordPress $wpdb batch queries

618.8k↑13.9%1PHP

Since Nov 2Pushed 7y ago2 watchersCompare

[ Source](https://github.com/matzeeable/wpdb-batch)[ Packagist](https://packagist.org/packages/matthiasweb/wpdb-batch)[ RSS](/packages/matthiasweb-wpdb-batch/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

wpdb-batch
==========

[](#wpdb-batch)

WordPress `$wpdb` batch `UPDATE` (for `INSERT` PR welcome). Never run multiple SQL queries - run one batch SQL query and increase your plugin performance.

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

[](#installation)

```
composer require MatthiasWeb\wpdb-batch:dev-master

```

Batch `UPDATE`
--------------

[](#batch-update)

Construct new instance with the following arguments:

ArgumentTypeDescription`$table_name``string`The table name`$index``string`The index column name which should be `CASE`'d`[$format_values]``array`An optional array with column name as key and format value. If none is given all format values are strings```
global $wpdb;
$wpbu = new MatthiasWeb\WpdbBatch\Update($wpdb->terms, 'term_id', array(
    'term_id' => '%d',
    'term_order' => '%d'
));
```

### `add($indexValue, $updates)`

[](#addindexvalue-updates)

Add a new update row. Returns: `this` instance for method chaining.

ArgumentTypeDescription`$indexValue``mixed`The index value for the `$index` column`$updates``array`An array with column name as key and new value```
$wpbu->add(1, array(
    'term_order' => 10
));

$wpbu->add(2, array(
    'term_order' => 11,
    'another_col' => 'test'
));
```

### `sql($chunkSize = 0)`

[](#sqlchunksize--0)

Get the SQL query as string. Returns: `array` if `$chunkSize` &gt; 0, otherwise `string`.

ArgumentTypeDescription`[$chunkSize=0]``int`The chunk sizeExample result:

```
UPDATE `wp_terms`
SET    `term_order` = ( CASE
                          WHEN `term_id` = 1 THEN 10
                          WHEN `term_id` = 2 THEN 11
                          ELSE `term_order`
                        end ),
       `another_col` = ( CASE
                           WHEN `term_id` = 2 THEN 'test'
                           ELSE `another_col`
                         end )
WHERE  `term_id` IN ( 1, 2 );
```

### `sqlArray($chunkSize = 0)`

[](#sqlarraychunksize--0)

Get the SQL queries as array. Returns: `array`.

ArgumentTypeDescription`[$chunkSize=0]``int`The chunk size### `execute($chunkSize = 0)`

[](#executechunksize--0)

Execute the batch update. Result: `array` with `failures` (`array` of SQL queries which failed), `updated` (`int`) and `success` (`boolean`).

Batch `INSERT`
--------------

[](#batch-insert)

The `INSERT` is not yet implemented because I didn't need this yet. Pull requests welcome.

License
-------

[](#license)

This repository is licensed under MIT license. The mechanism itself is inspired by [mavinoo/laravelBatch](https://github.com/mavinoo/laravelBatch).

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce54a1df28e33116ec4ceab17b5a197c5f6387061bc27096fab02aa0f12c4501?d=identicon)[matzeeable](/maintainers/matzeeable)

---

Top Contributors

[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (1 commits)")

---

Tags

composer-packagemysqlmysqliphpwordpresswordpress-developmentwpdb

### Embed Badge

![Health badge](/badges/matthiasweb-wpdb-batch/health.svg)

```
[![Health](https://phpackages.com/badges/matthiasweb-wpdb-batch/health.svg)](https://phpackages.com/packages/matthiasweb-wpdb-batch)
```

###  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)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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