Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Your 'homepage_carousel' sounds more to me like 'song'? You really don't want to name your post types after your usage (on the home page in a carousel), you want to name them after what they represent. –  MikeSchinkel Jan 7 '11 at 4:13

3 Answers 3

Hi @Dewayne:

You can't really "share" a post type; each post has one type.

But I'm more concerned maybe the 'homepage_carousel' architecture you've chose is not right and thus is leading you into all sorts of conundrums like wanting to share post types. Can you describe more in detail what a 'homepage_carousel' holds?

At first blush this sounds like a classic case of needing a taxonomy for your post_type='artist' called "Featured Locations" (maybe) and you use the tag "Home Page Carousel?"

If you can update your question to let me know why that won't work then I can help you more. Of it if will work then great!

share|improve this answer
    
Hi Mike, thanks for responding to my question. I have updated the question to elaborate a bit more, I hope I have explained enough for you to help me. Hear from you soon. –  DigitalSea Jan 6 '11 at 12:32
up vote 1 down vote accepted

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="<?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="<?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="<?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.

share|improve this answer

Custom post types and taxonomies are confusing for me too, but I think Mike's got your answer with his suggestion to use taxonomies here.

The carousel isn't a type of content you're wanting to add to the database, it's content in the database that you want to present. Your answer would then be a query that looks for an artist's (custom-post-type & taxonomy) albums (custom-post-type) with custom fields (learn more, buy cd, buy mp3), with the 'featured location' taxonomy.

Would love to hear other's thoughts on this as custom post types and taxonomies remain one of the things I find most confusing. In particular I'm not sure how to resolve the artist being both custom post type and taxonomy which I think is necessary in order to allow the extra meta you want as well as the interrelationships with the other data.

In terms of the videos, you may want to look at the post-formats coming up in 3.1 so you wouldn't need separate embed codes for each size, just a different display attribute.

I hope this is helpful to you or at least furthers the conversation.

Cheers!

share|improve this answer
    
Regarding Post Types and Taxonomies, you might want to read this: core.trac.wordpress.org/ticket/14513 (Be warned, I was on a bit of a rant given their 'edge case' response back to me.) –  MikeSchinkel Jan 7 '11 at 4:15
    
Thanks for sharing that Mike. A great read and the clearest illustration of what I've been trying to say, but haven't had the language for. Have to agree that it's not really an edge case given that it's turned into an issue with just about everything I've looked at recently. Haven't gotten to the bottom of the discussion yet, but here's hoping the last line is "Great, let's do it!" –  Christopher Jan 7 '11 at 18:49
    
Nice one Mike. I see you've been advocating some kind of post relationships functionality in the core, but received the typical Wordpress developer response: "This is not needed, build a plugin." most of the people involved in the development of Wordpress are sadly going to be its demise. I found this plugin: wordpress.org/extend/plugins/relation-post-types - anyone know how to get the data on the front end? I tried to use Scribu's posts 2 posts plugin, but I couldn't understand how it works. –  DigitalSea Jan 9 '11 at 3:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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