WordPress.org

Ready to get started?Download WordPress

Forums

How to link Songs to Albums as Custom Post type?? (3 posts)

  1. mimisayz
    Member
    Posted 3 years ago #

    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???

  2. Anointed
    Member
    Posted 3 years ago #

    This will give you a starting point:
    http://wordpress.org/extend/plugins/posts-to-posts/

    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.

  3. mimisayz
    Member
    Posted 3 years ago #

    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...

    $wpdb->show_errors();
    $albums = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'album' AND post_status = 'publish' ORDER BY post_date DESC", ARRAY_A);
    if($albums):
    // 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']);
    	}
    endif;

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

Topic Closed

This topic has been closed to new replies.

About this Topic