PHPackages                             hard-g/cpt-tax - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hard-g/cpt-tax

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hard-g/cpt-tax
==============

WordPress library that creates a taxonomy term corresponding to each item in a given Custom Post Type. Useful for mimicking post-to-post relationships.

v1.0.1(2y ago)0552↓100%GPL-3.0-or-laterPHP

Since May 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hard-g/cpt-tax)[ Packagist](https://packagist.org/packages/hard-g/cpt-tax)[ RSS](/packages/hard-g-cpt-tax/feed)WikiDiscussions main Synced 1mo ago

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

CPT-TAX
=======

[](#cpt-tax)

This is a library intended for use in WordPress plugins. The library allows you to ensure that each post of a custom post type is mirrored by a term in a custom taxonomy.

Use cases: An overview
----------------------

[](#use-cases-an-overview)

What is the purpose of this mirroring? WordPress famously does not have native support for post-to-post relationships. Many-to-many relationships only exist between taxonomy terms and posts. This library creates a workaround for this limitation.

As an example, imagine you are building a WordPress site about movies. You have three custom post types: Movies, Awards, and Actors. As part of your system, you'd like the ability to associate Actors with both Movies and Awards. Moreover, these relationships must be many-to-many: a single Actor could linked to many Movies, while a single Movie will likely be linked to many Actors.

In your plugin or theme, you would register a taxonomy corresponding to Actors. Then, tell this library to create a link between the taxonomy (say, `actor_tax`) and the post type (say, `actor_pt`):

```
\HardG\CptTax\Registry::register( 'actors', 'actor_pt', 'actor_tax' );
```

Each post in the `actor_pt` post type will be mirrored by a term in the `actor_tax` taxonomy. You can then associate an Actor with a Movie using WP's taxonomy tools:

```
// Fetch the term ID corresponding to the Actor post.
$actor_term_id = \HardG\CptTax\Registry::get_term_id_for_post_id( 'actors', $actor_post_id );

wp_set_object_terms( $movie_post_id, [ $actor_term_id ], 'actor_tax', true );
```

Later, if you want to query for Movies associated with the Actor, you would use a similar technique:

```
// Fetch the term ID corresponding to the Actor post.
$actor_term_id = \HardG\CptTax\Registry::get_term_id_for_post_id( 'actors', $actor_post_id );

$movies_with_actor = get_posts(
  [
    'post_type' => 'movie_pt',
    'tax_query' => [
      [
        'taxonomy' => 'actor_tax',
	'terms'    => $actor_term_id,
      ]
    ],
  ]
);
```

Similarly, if you want to display a list of Actors associated with a given Movie:

```
$actor_posts = array_map(
  function( $actor_term ) {
    $actor_post_id = \HardG\CptTax\Registry::get_post_id_for_term_id( 'actors', $actor_term->term_id );
    return get_post( $actor_post_id );
  },
  wp_get_object_terms( $movie_post_id, 'actor_tax' );
);
```

Methods
-------

[](#methods)

### `\HardG\CptTax\Registry::register( $link_key, $post_type, $taxonomy )`

[](#hardgcpttaxregistryregister-link_key-post_type-taxonomy-)

Sets up the link between the post type and the taxonomy. Call this sometime shortly after you've registered the taxonomy and the post type. `$link_key` is a unique identifier for this "pair", which you'll use whenever referencing the pair later.

### `\HardG\CptTax\Registry::get_post_id_for_term_id( $link_key, $term_id )`

[](#hardgcpttaxregistryget_post_id_for_term_id-link_key-term_id-)

Gets the ID of the post associated with a given linked term.

### `\HardG\CptTax\Registry::get_term_id_for_post_id( $link_key, $post_id )`

[](#hardgcpttaxregistryget_term_id_for_post_id-link_key-post_id-)

Gets the ID of the term associated with a given linked post.

Tips
----

[](#tips)

This library does *not* register the mirrored taxonomy for you. You'll have to do this yourself. In many cases, this taxonomy only meant to provide the links in the database, in which case it's recommended to make the taxonomy non-public:

```
register_taxonomy(
  'my_taxonomy',
  $my_post_types,
  [
    // ...
    'public' => false,
    'show_ui' => false, // Unless you want to be able to see it for diagnostic purposes in the Dashboard
    'show_in_rest' => false,
    // ...
  ]
);
```

If you leave the UI enabled, you may wish to disable creation of new terms (all term creation is handled by the library), while still allowing terms to be assigned in the UI to posts:

```
// ...
'capabilities' => [
  'manage_terms' => 'do_not_allow',
  'edit_terms'   => 'do_not_allow',
  'delete_terms' => 'do_not_allow',
],
// ...
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

1081d ago

### Community

Maintainers

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

---

Top Contributors

[![boonebgorges](https://avatars.githubusercontent.com/u/246627?v=4)](https://github.com/boonebgorges "boonebgorges (13 commits)")

### Embed Badge

![Health badge](/badges/hard-g-cpt-tax/health.svg)

```
[![Health](https://phpackages.com/badges/hard-g-cpt-tax/health.svg)](https://phpackages.com/packages/hard-g-cpt-tax)
```

###  Alternatives

[zenepay/filament-buddhist-date-picker

Laravel Filament DatePicker with Bhuddist Era plugin

214.8k](/packages/zenepay-filament-buddhist-date-picker)[workerman/stomp

1010.3k6](/packages/workerman-stomp)

PHPackages © 2026

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