0

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!

2

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");
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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