Working with attaching one custom post type to another
-
The way I ended up approaching the problem of attaching my Album cpt to an Artist cpt was to first check to see if there were any Artists created before allowing the user to create an Album. I’ll still need to do some more error handling (like what to do if the user deletes all Artists after an Album was attached to that Artist) before I try to convert this to a plugin and release it into the wild.
So the user clicks to add an Album and if there are no Artists they get an error message directing them to first add an Artist. If Artists are present, I populate a drop down list with the Artists. The user enters in the rest of the information about the Album. I dealt with the issue of being able to add a varying amount of tracks with a textarea with one track per line. I save the value of the Artist drop down and the tracks.
* On editing the Album I set the artist to be selected in the drop down.When I display the content on my page I simply loop the Artists and check for and loop Albums within that loop. I convert the tracks to an array then loop through the array to add a number (or whatever content needs to be in front of the track name).
One of the drawbacks with the way I have this set up currently is that the user can’t see which Albums are associated with the Artist they are editing. I could add this in at some point, I suppose. I also probably need to clean up my code to make it more efficient.
I’ll post my code when I get some time to separate it out from my functions.php. I may get to that this weekend, I just wanted to share at least a description of my solution.
Thanks!
Brett
- The topic ‘Working with attaching one custom post type to another’ is closed to new replies.