I have a Roster page which contains two sections. The first section contains the artist with their pictures, short bios, and website links; and the second section contains the combined videos of every artist in the roster.
Similar to this:
Normally, I’d create two separate post types; one for ‘artist’ and another for ‘artist videos’ but I was wondering if there was a way I can somehow combine the two? So in the admin panel, it would look something like this:
If possible, how would I go about doing this? Or am I over-thinking this (as I often do) and is there an easier way?
It would take some custom coding, but there is a way to keep both custom post types and link the artist and video post types together. It involves using the post_parent property of a post to make them hierarchical without combining the two.
I’m currently using the following code to attach one post type to another:
function parent_select ($parent_type) {
global $post;
global $wpdb;
$query = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type="{$parent_type}" AND post_status="publish" ORDER BY post_title";
$results = $wpdb->get_results($query, OBJECT);
echo '<select name="parent_id" id="parent_id">';
echo '<option value = "">None</option>';
foreach ($results as $r) {
echo '<option value="', $r->ID, '"', $r->ID == $post->post_parent ? ' selected="selected"' : '', '>', $r->post_title, '</option>';
}
echo '</select>';
}
Add this to a metabox on your video edit pages, passing your artist type as the parent type. It’ll create a dropdown box that will list all the artists you have. Just select one and update and that video now sees the artist you selected as a parent. After that, you can create a custom template to pull all the videos for any particular artist.