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.

Hy, im building a cinema site, in movie page i have a Custom Field that link's the actor page, when i add a movie and i link the actor, on the actor page i get the movie, now the problem is how can i add in this code the text "No movie by this actor", if no movie is selected i want to retrive automate That Text.

To retrive the movies i have this code.

<?php 
//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="';
    the_permalink();
    echo '" title="'.get_the_title().'">';
    ?>
    <img class="actor-img" src="/scripts/timthumb.php?src=<?php the_field('img'); ?>&h=110&w=75&zc=1" alt="<?php the_title(); ?>"  title="<?php the_title(); ?>"/>

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

// Reset Post Data
wp_reset_postdata();
?>

Anny help would be apreciate. Thanks in advance!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Something along these lines should work:

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

        <?php the_title();
        echo '</a></div>';
    endwhile; 
} else {
    echo("No movie by this actor");
}
share|improve this answer
    
Thanks @Toon Van de Putte it works –  Batman Feb 11 '13 at 14:42
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.