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'm creating a movie blog using WordPress.

I have Movie and Trailer custom post types and I want to add a Photo feature for this and I want to add a relationship between this photos and Movie CPT.

What the best way to handle this? Is custom field the answer? And manually add the movie post id on the custom field?

share|improve this question
    
possible duplicate of How Do I Use The Wordpress Plugin Posts 2 Posts by Scribu? –  kaiser Jul 5 '12 at 9:28
1  
It's not a dublicate, but it ends at the same place: "Posts 2 Posts". –  kaiser Jul 5 '12 at 9:28
add comment

1 Answer

Yes, Custom Fields is a good answer for that.

To make things easier there's a couple of plugins that can automate the process and create a nice interface for that.

One is Advanced Custom Fields, but its Repeatable Field is a premium add-on, so I'll show how to do it with another one.

Custom Content Type Manager

This plugin also manages Custom Post Types, but, if you already created yours, they'll appear as "externally created".

Anyway, it also handles Custom Fields and you can assign them to any CPTs.

Bellow, a snapshot of a Gallery CPT that has only the Title enabled, plus one repeatable field for Images and another field for RelationShip (this can be any post type: post, page, cpt, attachment).

enter image description here

You'll have to read the plugin documentation on how to implement those CF's with your Theme code.

Sample code on how to retrieve the repeatable image field named gallery_img:to_array:

$the_imgs = get_custom_field('gallery_img:to_array');
foreach( $the_imgs as $img )
{
    list( $url, $width, $height ) = wp_get_attachment_image_src( $img, 'thumbnail' );
    echo '<img src="' . $url . '" width="' . $width . '" height="' . $height . '"><br />'; 
}
share|improve this answer
    
will this also give a url for each photo? –  wpleet Jul 5 '12 at 12:21
    
@wpleet : Answer updated with sample code and plugin documentation links. –  brasofilo Jul 11 '12 at 2:32
add comment

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.