WordPress.org

Ready to get started?Download WordPress

Forums

Display random post custom field (3 posts)

  1. displaced2000
    Member
    Posted 5 years ago #

    I found and adapted this code from another post on this forum but i need some extra functionallity that i cant work out.

    <?php $rand_posts = get_posts('cat=8&numberposts=1&orderby=rand'); foreach( $rand_posts as $post ) : ?>
    <a href="<?php the_permalink() ?>" class="test1"><?php echo get_post_meta($post->ID, "testimonial", true); ?></a>
    <?php endforeach; ?>

    But not every post in category 8 have testimonials so i want to be able to skip the post with no entry. because at the minute i get a blank space when it returns a post with no testiomial.

    Thanks!

  2. displaced2000
    Member
    Posted 5 years ago #

    Its ok ive sorted it....

    found a very handy tutorial here

    that walked me through the entire process.

  3. Storyman
    Member
    Posted 5 years ago #

    This is a community where we share. How about sharing your insight?

Topic Closed

This topic has been closed to new replies.

About this Topic