Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

All of the answers I've found so far - here and elsewhere - involve creating a (custom) post - which would be 'overkill' because in this instance many of the 'terms' would only appear once.

Specific example to explain what I'm trying to accomplish:

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.

I (think I!) want to have one taxonomy of 'person' (i.e. so that Person A is only entered once) with other taxonomies of 'composer', 'lyricist' and 'presenter'. Then on the actual post for Song 1, Song 2, Show 1, etc. I have each person:relationship. A search for Person A would then show that (s)he is connected to:

Song 1, as 'composer';
Song 2, as 'lyricist';
Song 3, as 'composer' and as 'lyricist';
Show 1, as 'presenter'.

Alternatively, if I'm asking the impossible and have to relate through a 'person' custom post, is there an 'easy' (i.e. automatic) way to create it, i.e. when I'm inputting data for a song, show, etc. and just want to enter a name?

Should add that "No ... looked for ages (or tried clever ways) but haven't found a solution" is an acceptable answer. Not the one I was hoping for but at least it might convince me to stop looking / trying!

share|improve this question
1  
Neat question. I was going to suggest re-using people in each taxonomy, but you can't do that because of term slug conflict. It would be possible with post meta, but meta queries are less efficient.. –  helgatheviking Jul 26 '13 at 16:07
    
@helgatheviking: I think that's how I'll have to do it ... if the answer is "no" ... then use functions to see if the same person is in taxonomy A, taxonomy B, taxonomy C, .. etc. Hadn't really considered the slug conflict, will have to compare term text rather than slug. Seems like a lot of calculating and comparing for what should be a relatively easy task. (I can't be the only person who has needed to do a variant of this, surely???) –  Kevin4fm Jul 26 '13 at 21:15
    
I've never heard of trying to do this before though, so it doesn't strike me as a relatively easy task. ;) I would probably also make a People CPT and use that to limit the choices in a custom meta UI. Good luck! –  helgatheviking Jul 27 '13 at 0:46

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
Not the answer I hoped for ... but the one I expected. Your solution seems a good one. I'll have to work to learn how to implement it, but not as hard in the long term as creating individual 'person' posts and once I have it the use of processing resource will be dramatically less than how I was thinking of approaching it (essentially running a "Person A = 'conductor'; Is 'Person A' linked to any other post in any role" query every time) and one of the objects of the project is to make me learn new stuff! :-) And once I know how, I suspect I'll use it a lot! Many thanks for the solution. –  Kevin4fm Jul 27 '13 at 7:43
    
You are welcome. On how to create a metabox you can find a lot here in wpse try. On how create a custom table and use it wptuts has a great tutorial in 6 articles you'll find it here –  G. M. Jul 27 '13 at 12:49

If you want an out of the box way to do this I'd say use Advance Custom Fields, it has a friendly UI and it's really simple to use and understand, you can either choose a relationship type or a post object then with some work on your theme you'll get the relation between post types or taxonomies.

http://www.advancedcustomfields.com/resources/field-types/relationship/

http://www.advancedcustomfields.com/resources/field-types/post-object/

Else I'd go for G. M. answer.

share|improve this answer
    
Abject apologies for the delay in acknowledging your suggestion. Upgrade to WP 3.6 etc. made me go off at tangents. From a brief examination of "ACF" it appears - at first glance at least - that it's still necessary to create custom posts then link them via relationships. This is the step I'm trying to avoid (cos it'll take ages, for very little benefit!) However, I might not have 'got' it yet, so I'll re-examine your suggestion in greater depth as soon as I get time. Once I have, I'll leave another message here in case it helps others too! :-) –  Kevin4fm Aug 21 '13 at 14:22

So here is the thing with a structure like this. It goes both ways. Person A can be the composer of poem 1, and singer of song 2, and you can associate them via metas. However, the thing is, Person A him/herself is a composer & singer to begin with. So you might want to do something like this:
Create Person as a CPT, create new Persons and add traits to them like singer or composer. Then create CPT for different types of entertainment, like one for TV shows and one for Poems. And then link Person via a meta field.

share|improve this answer
    
Except that (I'm guessing) "CPT" stands for "Custom Post Template" - so, a post, which I'm trying to avoid creating, but instead doing it through taxonomies where 'Person A' is simply a term. I want to not create a post per person because I expect 100s of people and that: most people will be involved in 1 show or song in 1 capacity; a small number of people will be involved in multiple songs or shows; relatively few people will be involved in multiple songs and multiple shows in multiple capacities ... but (kind of unfortunately) ... showing their multiple involvement is important. –  Kevin4fm Jul 26 '13 at 14:42
1  
CPT = Custom Post Type. –  helgatheviking Jul 26 '13 at 15:35
    
@Michael4fm regardless of that, the person has a two-level relationship. First the connection of the person to whatever object you're linking him/her to, and second, what traits does this person possesses. I'm suggesting a two way relationship to pave way for scalability. If you're only interested in one way relationship, you can still keep that without the trait on the person him/herself –  Angela Jul 27 '13 at 9:17
    
@Angela I think a taxonomy relationship would still allow 2 way relationships - one could search for posts the term "Person A" is connected to so find Song 1, Song 2, Show 1, etc. I understand what you've suggested but I literally need to store just "Person A"s name. Creating a post just to do that seems overkill. And, if in the future I find I'd like to record more than just the name for a few people, I could create a CPT - say 'Profile' - for just those few people and link it in the same way as a song or a show. LOL. What are the chances that now I'll need to do just that! –  Kevin4fm Jul 27 '13 at 17:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.