What it does

Relating one piece of content to another in WordPress usually means custom fields, meta queries, or a table of your own. Shadow Terms uses what WordPress already has. For each post type you choose, it registers a taxonomy that mirrors it. Create an Organization, and a matching term appears in an organization_connect taxonomy. Assign that term to a Person or a Press Release in the editor, the way you’d assign a category, and the two are related.

The terms keep themselves in step. Rename a post and its term is renamed. Change the slug and the term’s slug follows. Delete the post and the term goes with it. There is nothing to sync by hand, and the “Add New” control is hidden on shadow taxonomies, since they manage themselves.

How it works

Support is added in code, where the post type is registered. This says Organizations get a shadow taxonomy, and People and Press Releases can be assigned to it:

// Register the organization post type as usual.
register_post_type( 'organization', $args );

// Give it a shadow taxonomy, and say which post types use it.
add_post_type_support(
	'organization',
	'shadow-terms',
	array( 'person', 'press-release' )
);Code language: PHP (php)

From then on, every published Organization has a term in organization_connect, offered in the Person and Press Release editors under “Organizations”.

Related content comes back with an ordinary tax_query. Everyone who has queried WordPress by category already knows how:

// Everyone related to the organization with the slug 'happy-prime'.
$people = new WP_Query(
	array(
		'post_type' => 'person',
		'tax_query' => array(
			array(
				'taxonomy' => 'organization_connect',
				'field'    => 'slug',
				'terms'    => 'happy-prime',
			),
		),
	)
);Code language: PHP (php)

Good for

  • A pair of post types. People and the projects they work on, speakers and their webinars, venues and their events.
  • A record that gathers everything about one thing. A program and the meetings, decisions, and documents about it, collected over years. One term, and every piece is findable from the program.
  • Curated sets. A gift guide and its products, a travel guide and its places, a recipe and the beers it goes with.
  • Post types you didn’t write. Products from WooCommerce or listings from a jobs plugin connect the same way as your own, since they’re only post types.

What to know

  • It’s a developer’s tool. Support is declared in a theme or plugin, not in a settings screen.
  • The relationship lives in WordPress’s own tables. No new tables, and the usual term caching applies.
  • Shadow terms follow their post type’s visibility. If the post type isn’t public in the REST API, its terms aren’t shown to unauthenticated users either.
  • The shadow taxonomy’s arguments can be filtered, for anything the defaults don’t cover.
  • For a one-to-one relationship, a plain post meta field may be simpler.

Terms are the relationship.

Questions about Shadow Terms for your project?

Interested in contributing to Shadow Terms?

Tell us what you’re working on