1
votes

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();
?>
1

1 Answers

1
votes

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' ) );