Support » Plugins » Hacks » Post type inside another post type

  • Resolved madsrh123


    I need help “linking” one post type to another.

    I’ve got one post type called ‘album’. This contains the title of the album and the track titles entered into a text field with unique names (track1, track2, …).

    Then I’ve got another post type ‘lyrics’ with more information about each song (text, file attachments, creator information, …).

    Inside ‘lyrics’ I need to be able to select which track I want to add information about.

    How can I do that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    You can store the ID of the related lyrics post in the post meta of album, and if need be, store the “parent” ID of the album post in the post meta of lyrics.

    bcworkz -> Thanks! But I’m not sure I understand. Can you elaborate as to how I would set this up?

    Moderator bcworkz


    Postmeta tables are used to store any arbitrary data related to a specific post. Use update_post_meta() to add or update the data, and get_post_meta() to retrieve the data. This is actually where the custom field data is stored, but your script can also use the table independent of the custom field meta boxes. It’s also possible to store arrays as well as individual values, so storing complex data structures is possible.

    Exactly how you can make use of this is highly variable depending on your specific implementation. I imagine much of your process would hinge upon creating a lyrics post. Besides entering lyrics, one needs to choose which album post and track the lyrics are for. That choice needs to be stored with the lyrics post of course. It could be entered as a custom field, or it could be through a custom metabox.

    For instance, once an album is selected, another drop down could be populated with tracks that do not have associated lyrics. This would require the use of AJAX though.

    At the same time the lyric post is saved with it’s relationship to album and track, the reverse relationship could be stored with the album and track post telling you which lyric post is associated with the track. Thus given any one bit of information, the rest of the relationship can be determined.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post type inside another post type’ is closed to new replies.