Reputation: 11
I'm trying to display a random post from a custom post type where the posts have a category of "Images".
This is my code so far, I don't understand why it's not working?
<?php
$the_query = new WP_Query( array ( 'orderby' => 'rand', 'post_type' => 'testimonial', 'posts_per_page' => '1', 'category_name' => 'images' ) );
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="feature boxed testimonials">
<?php the_content(); ?>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
Upvotes: 1
Views: 580
Reputation: 1578
I think you have added page number (posts_per_page
) in string. Give the number in integer
as below may help.
$the_query = new WP_Query( array ( 'orderby' => 'rand', 'post_type' => 'testimonial', 'posts_per_page' => 1, 'category_name' => 'images' ) );
Upvotes: 1