WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post type inside another post type (4 posts)

  1. madsrh123
    Member
    Posted 1 year ago #

    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?

  2. bcworkz
    Member
    Posted 1 year ago #

    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.

  3. madsrh123
    Member
    Posted 1 year ago #

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

  4. bcworkz
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags