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 have this code that picks a random testimonial post.

        $quote_args = array(
            'post_type' => 'post',
            'category' => 'quote',
            'orderby' => 'rand',
            'posts_per_page' => 1

        $quote  = new WP_Query($quote_args);


    <p id="quote">
        <?php the_content_rss(); ?>
        <span><?php echo the_title(); ?></span>



The testimonials are posts with a category of 'quote', the title of the post is the name of the person.

I have other posts in the site that have other categories but only the testimonial posts have a category of 'quote'.

The code works but I'm getting a random post picked from all the posts and not just the post's with a quote category.

Can anyone see a reason why I getting this, or any other reason this is happening

share|improve this question
up vote 2 down vote accepted

There's no such parameter as category for WP_Query, so WP is ignoring it. You should use category_name, where the value is the slug of the category.

share|improve this answer

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.