Is there a (relatively easy!) way to create relationships between taxonomies WITHOUT needing a post as an intermediary

Using standard WordPress functionalities this is, simply, not possible, unless using complicated and poorly performing tricks.

The method I suggest you is to create your custom table where store relationship.

It should consists of 5 columns:

person_id | post_id | post_type | taxonomy | term_id

Now, copying out your example:

Person A may be the composer of Song 1;
Person A may be the lyricist of Song 2;
Person A may be both the composer and lyricist of Song 3;
Person A may have been the presenter of Show 1.

and assuming:

'Person A' is a term of 'people' taxonomy with term_id 66
'Composer' is a term of 'talents' taxonomy with term_id 30
'Lyricist' is a term of 'talents' taxonomy with term_id 40
'Presenter' is a term of 'talents' taxonomy with term_id 50
'Song 1' is a post with the id 1
'Song 2' is a post with the id 2
'Song 3' is a post with the id 3
'Show 1' is a post with the id 9

To rapresent the relationships in your example we need 5 rows in the table

66 | 1 | 'post' | 'talents' | 30
66 | 2 | 'post' | 'talents' | 40
66 | 3 | 'post' | 'talents' | 30
66 | 3 | 'post' | 'talents' | 40
66 | 9 | 'post' | 'talents' | 50

Knowing a person id you know all his/her talents and to which posts are related. Same way, knowing a post id you know all people related and which is the talent involved in that particular post.

Getting and showing data it’s a cinch: once people, talents, song and shows are wordpress standard entities (posts, terms) you have to do nothing to create url for show them selectively and you can make the better use of template hierarchy as well. Getting custom associations is very easy, few lines of sql and you are done.

Store custom associations is a bit harder: not being part of wordpress core you have to built entirely the UI for the scope. Nothing impossible: you need just a metabox with some rows (or better the ability to dinamically add rows) and for every row two select menus: one for people one for talent.

Note that this method allow link people with every post type and every taxonomy: maybe now you will use only standard post type and ‘talents’ but in the future… I always like design in a flexible manner to avoid refactoring at every change.

Hope it helps.

Leave a Comment