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

    <?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="quote">
        <?php the_content_rss(); ?>
        <span><?php echo the_title(); ?></span>
    </p>

        <?php
            endwhile;
            endif;

            wp_reset_postdata();
        ?>

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

1 Answer 1

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

 
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.