3

I have an audio website and I want to allow users to make custom playlists from posts.

I am using posts as Albums which contains the Tracks. I thought of creating a custom post type and using it to hold a user select playlist based on the default posts.

Is this a good idea or is there a better way to allow users to create custom playlist.

Notes:

  • I had a look at this tutorial. It is what I'm looking for but for individual tracks in the post.
  • The audio is stored in arrays in custom fields, i.e custom_audio{ audio=>"name", url=>"www.text.com"}
4
  • Can you point me what do you mean " wordpress post as a album" what it means? you place in your post a links to mp3 or you upload a mp3 (any other format) to your post? Commented Nov 20, 2012 at 19:29
  • i am using the post custom fields to contain all the tracks in the album, each post contains different albums
    – user5601
    Commented Nov 20, 2012 at 19:40
  • 1
    This question seems overly broad. Commented Nov 20, 2012 at 19:50
  • am storing audio in arrays in custom fields, i.e custom_auido{audio=>"name", url=>"www.text.com"}, would it be good practice to use custom post type to store users custom playlist or create a custom database table.
    – user5601
    Commented Nov 20, 2012 at 19:54

1 Answer 1

1

What you are looking for is to create a relationship between a Custom Post Type and the Post type.

If your users have editing capability for the CPT, then yes, it's a good idea to use the CPT's to hold the information about the Albums (normal posts).

The easiest/fastest solution is to use a plugin.

Posts to Posts is meant exclusively for this (my emphasis):

This plugin allows you to create many-to-many relationships between posts of any type: post, page, custom etc. A few example use cases:

  • manually curated lists of related posts
  • post series
  • products connected to retailers
  • etc.

Additionally, you can create many-to-many relationships between posts and users. So, you could also implement:

  • favorite posts of users
  • multiple authors per post
  • etc.

And another one is Advanced Custom Fields. As I'm a regular user, I can illustrate its use for this case.

Create a Field Group with the following configuration:

advanced-custom-fields configuration
click to enlarge

That results in this:

advanced-custom-fields result

The result snapshot have a little trick though. The normal box that ACF generates has a very short height.
To modify the box height, use the following code in your theme's functions.php file, or a custom plugin which makes this theme independent.

/** 
 * ADJUST THE VALUE OF 'playlists' TO THE CUSTOM POST TYPE SLUG
 * ADJUST THE VALUE OF #acf-album_posts TO MATCH THE FIELD NAME 
 */ 
add_action('admin_head-post.php', 'wpse_73351_admin_head');
add_action('admin_head-post-new.php', 'wpse_73351_admin_head');

function wpse_73351_admin_head()
{
    global $post;
    
    // Not our post_type, do nothing
    if ( 'playlists' != $post->post_type )
        return;     
    ?>
        <style>
            #acf-album_posts select {
                height: 400px !important;
            }
        </style>
    <?php
}

Finally, read the plugin's documentation to see how to grab the album_posts field value and play that funky music :)

2
  • thanks for the answer, just wondering would it be possible to link a certain track from the an album (post) to a user, that is saved in the custom fields.
    – user5601
    Commented Nov 22, 2012 at 18:29
  • That's another question... Try first, ask later :)
    – brasofilo
    Commented Nov 22, 2012 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.