Support » Fixing WordPress » How to link Songs to Albums as Custom Post type??

  • Hi all,
    I am pulling my hair out trying to figure this one out… I have a custom post type of Albums, that when I add a new album, I’d like to link songs (post type Songs) that are already in the database to the given album as a track list… I have the 2 post types, but I have no clue how to add a pick list or some kind of write field where i can add songs to the album in the manner that one can add Images, video or sound to a post… Any ideas???

Viewing 2 replies - 1 through 2 (of 2 total)
  • This will give you a starting point:

    Right now posts-to-posts simply creates a one way or bidirectional relationship between post types. However in its current alpha stage, it only relates an individual object from a post type to another.

    I know that Scribu plans on expanding the plugin in the future to work with multi-relationships from a given post type, but it’s not there at the moment. It’s possible the logic is already in the core, but the UI is a single pick right now.

    Hope it helps.

    ** if you do manage to hack it for multi-relational objects, I would love to see how you did it. I’ve been playing around on that part myself for some time now.

    Hi Thank you so much, I managed to hack it in the functions file when I define the metaboxes, I basically make a wpdb request for custom post type and the create a select box with the values, with a little help from Rilwis meta box script. I’ve even hacked his script a bit to suit my purpose. So far I’ve only gotten songs to refer to albums, and I’m running short on time to figure the other direction out Album to songs… here is my hack so far… not pretty at all…

    $albums = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'album' AND post_status = 'publish' ORDER BY post_date DESC", ARRAY_A);
    // create empty first select box with zero value
    	$album_select[] = array('value' => '', 'name' => 'none');
    	// add album to select 'options' array
    	foreach($albums as $album){
    		$album_select[] = array('value' => $album['ID'], 'name' => $album['post_title']);

    then just tack the array on to the meta box script for options…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to link Songs to Albums as Custom Post type??’ is closed to new replies.