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?


1 Answer 1


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 />'; 
  • will this also give a url for each photo?
    – tiltdown
    Commented Jul 5, 2012 at 12:21
  • @wpleet : Answer updated with sample code and plugin documentation links.
    – brasofilo
    Commented Jul 11, 2012 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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