Is It Possible To Have Shared WordPress Custom Post Types?

I am developing a website for a record label and the basically it uses quite a few custom post types for various pieces of information. My problem is that I feel the same bits of information are being repeated, rather than shared.

I have an artists custom post type, however on the homepage there is a carousel with artists as well but different pieces of information to display. So I have a “homepage carousel” custom post type of which I have to enter the artist names and info, as well as an image and also an “artists” custom post type with some of the same information entered again.

The client is probably not going to like having to enter the same information into multiple custom post types all of the time, is it possible to make a post type inherit from another?

So I can tell my “homepage carousel” post type to inherit from an artists post type so the artist information is shared and doesn’t have to be re-entered again?

At present I have created a custom taxonomy called artists and entered in all possible artist names and then for example in the “homepage carousel” post type I select the artist in the right hand side as being the category. This works well in a way, however you still need to enter a title or you get some “Autosave” nonsense being saved as the title which will make editing and sorting difficult down the track. Is there perhaps a way to set the title as the category “artist” that has been selected?

Let me know if you don’t quite understand and I’ll try and elaborate a bit more. I basically want to share a centralised list of artists and information of which I can inherit from in other post types.

* Update *

A bit more elaboration on my original question.

Here are my defined post types and the information that they hold. What I want to do is set up a shared relationship between my “artists” post type and other post types that relate to the artist in some way.

Post type: artists
Fields: Title, Wysiwyg Editor, Featured Image, Facebook URL, Twitter Username, Website URL.

Post type: homepage_carousel
Fields: Title, Learn More Link, Buy CD Link, Buy MP3 Link
A carousel item corresponds to an artist defined in the artists post type above. So the ability to relate this post type to the artists post type is what I want.

Post type: videos
Fields: Title, Video Embed Code (455px), Video Embed Code (466px), Video Embed Code (608px), Video description.
A video item corresponds to an artist defined in the artists post type. I want to be able to assign a video to an artist.

As you can see I want to basically set up a many-to-one relationship or is it one-to-many relationship? One of those (I think). I’ve started messing with this plugin: http://wordpress.org/extend/plugins/posts-to-posts/ – but I don’t quite understand how to properly use it yet, I think it’s something that I want. So if someone has used this before, your help would be appreciated.

Whilst I am aware of custom taxonomies and terms, I think that what I am wanting goes way beyond the requirements I am seeking as I am dealing with multiple pieces of information and merely want to tie 2 post types together some how.

3 Answers
3

I have partly solved my own question so-to-speak. I’ve been trying to get post type relationships working for ages and the plugin relation post types as mentioned in my comment to Christopher’s answer. It is far from perfect, but I worked out how to get this plugin: http://wordpress.org/extend/plugins/relation-post-types/ – working (albeit not that pretty).

The following code will fetch a homepage carousel item and then an associated artist name. This can be modified to get related post meta as well. I wanted to use Scribu’s posts 2 posts plugin, but couldn’t work out how to use it.

$carousels = get_posts(array('post_type' => 'homepage_carousel'));  
$counter   = count($carousels);
$increment = 0;
foreach($carousels as $carousel):
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $carousel->ID ), 'large' );
    $related_ids = rpt_get_object_relation($carousel->ID, array('artists'));
    foreach ($related_ids as $related_id) {
        $related_post[] = get_post($related_id);   
    }
<li style="background: transparent url(<?php echo $image[0]; ?>) no-repeat;">
<div class="carousel_content">
    <p class="large_heading"><?php echo $related_post[$increment]->post_title; ?></p>
    <p class="carousel_meta">
        <?php if (get_post_meta($carousel->ID, 'learn_more_link', true)): ?>
            <?php $link = true; ?>
            <a href="https://wordpress.stackexchange.com/questions/6404/<?php echo get_post_meta($carousel->ID,"learn_more_link', true); ?>">Learn More</a>
        <?php endif; ?>
        <?php if (get_post_meta($carousel->ID, 'buy_cd_link', true)): ?>
            <?php $link2 = true;  ?>
            <?php if ($link): ?> | <?php endif; ?>
            <a href="https://wordpress.stackexchange.com/questions/6404/<?php echo get_post_meta($carousel->ID,"buy_cd_link', true); ?>">Buy CD</a>
        <?php endif; ?>
        <?php if (get_post_meta($carousel->ID, 'buy_mp3_link', true)): ?> 
        <?php if ($link2 || $link): ?> | <?php endif; ?><a href="https://wordpress.stackexchange.com/questions/6404/<?php echo get_post_meta($carousel->ID,"buy_mp3_link', true); ?>">Buy MP3</a>
        <?php endif; ?>
        </p>
</div> 

As you can see this is very hacky and by no means a definitive solution. It worked for me, but I am still unhappy with how the above code works. To get associated post meta it would need more code.

As there is no answer, should this perhaps become a wiki more than a question perhaps? As the solutions listed here will not always be current as WordPress is constantly evolving and new plugins being released.

Leave a Comment