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.

I want to show one randomly picked testimonial on a page.

Each testimonial is a post with a category of 'quote'.

Each post has a custom field named 'who' with a name.

I'm trying to use this code.

<div id="introBottom" class="group">
      <?php
      $quote_args = array(
                'post_type' => 'post',
                'category' => 'quote',
                'orderby' => 'rand',
                'showposts' => 1
            );

            $quote  = new WP_Query($quote_args);

            if($quote->have_posts()):
                while($quote->have_posts()):
                    $quote->the_post();
                                ?>
                                <p id="testimonial">
                                <?php echo the_content(); ?>
                                <span><?php echo get_post_meta($post->ID, 'who', true); ?></span>
                                 </p>

</div>
share|improve this question
    
And what is wrong? You are using a deprecated parameter, and your if and while loops are not closed, but query works. –  s_ha_dum Apr 12 '13 at 14:18
    
Sorry it's been along day, if I close the loop it works - which parameter is deprecated - showposts. Also is it possible to get the contents without the surrounding p tags. –  user668499 Apr 12 '13 at 14:28
    
The {tax} => slug parameter is deprecated (but still works) in favor of tax_query. –  s_ha_dum Apr 12 '13 at 15:52
add comment

1 Answer

up vote 1 down vote accepted

Assuming - you saved the post in the "quote" type - you actually set and save a "who" meta for those post - you forgot to paste the close section of the loop, as s_ha_dum stated, your code should work.

Like this

<div id="introBottom" class="group">
      <?php
      $quote_args = array(
                'post_type' => 'post',
                'category' => 'quote',
                'orderby' => 'rand',
                'posts_per_page' => 1
            );

            $quote  = new WP_Query($quote_args);

            if($quote->have_posts()):
                while($quote->have_posts()):
                    $quote->the_post();
                                ?>
                                <p id="testimonial">
                                <?php echo the_content(); ?>
                                <span><?php echo get_post_meta($post->ID, 'who', true); ?></span>
                                 </p>
<?php
endwhile; 
endif;
?>
</div>

posts_per_page replace showposts

share|improve this answer
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.