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


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.

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.