WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building a cinema site, I came with a problem, let me explain:

  • Movies- are stored in Post's
  • Actors- are stored in Post Type - persoane ( taxonomy= lista)
  • Serials - are stored in Post Type - serial ( taxonomy= seriale)

I use Advance Custom Field to link the Person to the movie -

enter image description here

AFC (http://www.advancedcustomfields.com/)

How i add: I add new actor post to post type ( persoane), after i add the movie( in post's), in sidebar(post's, movie page) i link the actor (http://i49.tinypic.com/a8800.jpg). After i Link the actor on the actor page it display the movie's that actor play in

enter image description here

I use this code to do that

//create new loop query for films by this actor
$movies = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'distributie' AND meta_value LIKE '%".get_the_ID()."%'");
$the_query = new WP_Query( array( 'post__in' => $movies) );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<div class="actor-box-related"><a class="actor-titlu" href="';
    echo '" title="'.get_the_title().'">';
    <img class="actor-img" src="/scripts/timthumb.php?src=<?php the_field('img'); ?>&h=90&w=60&zc=1" alt="<?php the_title(); ?>"  title="<?php the_title(); ?>"/>

    <?php the_title();
    echo '</a></div>';

// Reset Post Data

The problem:

I create a Post Type - serial where I add the Serials (Ex: heroes,prisonbreak... )

How can i display on the actor's page the serials that actor play in. The custom_field for serials is "distributie_serial" - i change in that code but no sucess, it did not work.

The up code get me only the movies from post's, how can i get the movies from that PostType (serial).

Can I put both together to get movies and serials? Or how can i display the serial's on actor page, and IF no movie or serial is atach retrive the text "No movies for this actor"

Thanks in advance for those who help me.

share|improve this question
I see you're using timthumb.php, considering the major security risks of using it, I'd advise you use add_image_size and the_post_thumbnailinstead. Also your 'distributie' post meta should be a custom taxonomy called 'distributie'. – Tom J Nowell Feb 4 '13 at 12:14
distributie - is the custom field where i ad the actors in post's page. – Batman Feb 4 '13 at 12:17
You should use a custom taxonomy not a custom field. A taxonomy UI will be provided automatically for you to select from – Tom J Nowell Feb 4 '13 at 12:19
And if i will go with the custom field, how can i do that, my site is build now i canot chage entire site, Tom J Nowell , anny solution to get the serial from that PostType ? I think i have to change somting in that link $movies = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'distributie' AND meta_value LIKE '%".get_the_ID()."%'"); – Batman Feb 6 '13 at 2:41
What does var_dump($movies); gives you? An array? – brasofilo Feb 6 '13 at 21:46


i resolve a problem, a liitle question, how can i get the text if nothing is selected in custom field ( distributie_serial). Ex: no serial for this actor.

This is the Code that works.

$seriale = get_posts(array('post_type' => 'serial',
     'meta_query' => array(
                     array('key' => 'distributie_serial', // name of custom field
                           'value' => '"' . get_the_ID() . '"',
                           'compare' => 'LIKE'))
<?php if( $seriale ): ?>
<?php foreach( $seriale as $serial ): ?>
<div class="actor-box-related">
<a class="actor-titlu" href="<?php echo get_permalink( $serial->ID ); ?>">
<img class="actor-img" src="/scripts/timthumb.php?src=<?php echo get_field('imagine_serial', $serial->ID); ?>&h=90&w=60&zc=1" alt="<?php echo $photo['alt']; ?>" />
<?php echo get_the_title( $serial->ID ); ?>

<?php endforeach; ?>
<?php endif; ?>
share|improve this answer
<?php endforeach; else : // text when there's no posts endif; ?> – Maikal Sep 4 '15 at 15:41

Your Answer


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.