PHPackages                             hokoo/wpconnections - 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. hokoo/wpconnections

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

hokoo/wpconnections
===================

A library for many-to-many relationships in WordPress

3155[5 issues](https://github.com/hokoo/wpConnections/issues)[1 PRs](https://github.com/hokoo/wpConnections/pulls)PHPCI failing

Since Feb 7Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/hokoo/wpConnections)[ Packagist](https://packagist.org/packages/hokoo/wpconnections)[ RSS](/packages/hokoo-wpconnections/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (24)Used By (0)

WP Connections: post-to-post connections for WordPress
======================================================

[](#wp-connections-post-to-post-connections-for-wordpress)

[![PHP CS](https://github.com/hokoo/wpConnections/actions/workflows/php-cs.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/phpunit.yml)[![PHP WordPress Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests.yml)[![Dockerfile Unit Tests](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml/badge.svg)](https://github.com/hokoo/wpConnections/actions/workflows/wp-unit-tests-docker.yml)

- [Why wpConnection?](#why-wpconnection)
- [Quick Start](#ok-what-should-i-do-to-start-using)
- [WIKI](https://github.com/hokoo/wpConnections/wiki)

wpConnections allows to link posts in WordPress by graph-like connections. The library provides such connection properties as:

- direction (from, to)
- from post id
- to post id
- order
- meta data.

Connections belong to a Relation and never exist out. The relation has properties:

- cardinality (1-1, 1-m, m-1, m-m)
- from post type
- to post type
- direction type (from, to, both)
- duplicatable (whether may have same connections)
- closurable (whether may have the same post on from and to).

> **EXAMPLE.** There are four CPT: `magazine`, `issue`, `article` and `author`. Magazine posts may have connections with some Issues (one-to-many type) so that the Issues constitute the Magazine.
> The Issues in turn have connections with Articles (one-to-many as well). But an Author might have been linked with many Articles, and an Article might have many connections with Authors (many-to-many).

Why wpConnection?
-----------------

[](#why-wpconnection)

It can be used as multiple installed library being parts of different plugins in a WordPress installation. All you need is creating a client instance for your application. Every client has its own tables and REST API hooks, and does not influence to another clients.

Ok, what should I do to start using?
------------------------------------

[](#ok-what-should-i-do-to-start-using)

> Full documentation is available on [Wiki project pages](https://github.com/hokoo/wpConnections/wiki).

Add the package

```
composer require hokoo/wpconnections
```

So, you have to create client instance...

```
use iTRON\wpConnections\Client;

$wpc_client = new Client( 'my-app-wpc-client' );
```

...and relations for your connections.

```
use iTRON\wpConnections\Query;
$qr = new Query\Relation();
$qr->set( 'name', 'post-to-page' );
$qr->set( 'from', 'post' );
$qr->set( 'to', 'page' );
$qr->set( 'cardinality', 'm-m' );

$wpc_client->registerRelation( $qr );
```

Ok, now you can create connections inside the relation.

```
$qc = new Query\Connection();
$qc->set( 'from', $post_id_from );
$qc->set( 'to', $post_id_to );

$wpc_client->getRelation( 'post-to-page' )->createConnection( $qc );
```

Since you have initialized new client, its REST API endpoints are available.

`http://cf7tgdev.loc/wp-json/wp-connections/v1/client/my-app-wpc-client/`

Local Development
-----------------

[](#local-development)

### Prerequisites

[](#prerequisites)

- Windows 10 or later (WSL2), or Linux, or MacOS
- Docker Desktop, Docker Compose
- Make

### Installation

[](#installation)

1. Clone this repo to the **Ubuntu disk space**. Location path should look like `\\wsl$\Ubuntu-20.04\home\username\path\to\the\repo`.
2. Make sure you have `make` installed in your system. If not, run `sudo apt install make`.
3. Make sure you have installed Docker Desktop with configured WSL2 support if you are using Windows.
4. Add `127.0.0.1 wpconnections.local` to the hosts file (on the host machine).
5. Run folowing command in the root directory to install the project:

```
bash ./local-dev/init.sh && make tests.init && make docker.up && make dev.install
```

### Running the test suites

[](#running-the-test-suites)

The project ships with a dedicated `Dockerfile.phpunit` image that bundles Composer, the WordPress test library and an embedded MariaDB server so the entire PHPUnit stack runs inside a single container locally and in CI. After the installation step you can run all tests from the project root with:

```
make tests.run
```

Behind the scenes this calls `docker compose` with the `phpunit` service defined in `local-dev/docker-compose.yml`. The service no longer depends on any other containers—the entrypoint spins up MariaDB and configures the WordPress test library on demand—so these commands can be executed anywhere Docker is available. You can also run the individual commands manually, for example:

```
docker compose -f local-dev/docker-compose.yml run --rm phpunit composer run phpunit
docker compose -f local-dev/docker-compose.yml run --rm phpunit vendor/bin/phpunit -c php-wp-unit.xml
```

The same Dockerfile is also used by the optional GitHub Actions workflow defined in `.github/workflows/wp-unit-tests-docker.yml`, allowing you to compare its output against the long-standing `wp-unit-tests.yml` pipeline before switching over entirely. You can pin WordPress to a specific release by passing `--build-arg WP_VERSION=6.5.2` (or any other version number) when building the image.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96.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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3988fe121d93b3ce7fb819c278cf7f19bf40411db2a1a57bbd4ae6ea4ca3eedc?d=identicon)[hokoo](/maintainers/hokoo)

---

Top Contributors

[![hokoo](https://avatars.githubusercontent.com/u/16269260?v=4)](https://github.com/hokoo "hokoo (200 commits)")[![renakdup](https://avatars.githubusercontent.com/u/9306079?v=4)](https://github.com/renakdup "renakdup (8 commits)")

---

Tags

post-to-postwordpresswp-connectionswp-custom-relationswp-posts-to-postswp-relations

### Embed Badge

![Health badge](/badges/hokoo-wpconnections/health.svg)

```
[![Health](https://phpackages.com/badges/hokoo-wpconnections/health.svg)](https://phpackages.com/packages/hokoo-wpconnections)
```

###  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)
