在自定义帖子类型中显示类别中的随机帖子

时间:2018-06-27 12:35:47

标签: php wordpress

我正在尝试显示自定义帖子类型的随机帖子,其中帖子的类别为“图片”。

到目前为止,这是我的代码,我不明白为什么它不起作用?

<?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 个答案:

答案 0 :(得分:1)

我认为您已经在字符串中添加了页码(posts_per_page)。如下提供integer中的数字可能会有所帮助。

$the_query = new WP_Query( array ( 'orderby' => 'rand', 'post_type' => 'testimonial', 'posts_per_page' => 1, 'category_name' => 'images' ) );
相关问题