Possible to combine two custom post types?

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.

Leave a Comment