Php 返回带有get_posts()的随机帖子;在Wordpress中

Php 返回带有get_posts()的随机帖子;在Wordpress中,php,wordpress,Php,Wordpress,我目前正试图从Wordpress中的自定义帖子类型返回一篇随机帖子。目前,它返回的所有内容都是在该自定义帖子类型中发布的最后一篇帖子。我目前正在使用此代码获取帖子: <?php $posts = get_posts(array('posts_per_page' => 1, 'order_by' => 'rand', 'order' => 'ASC', 'post_type' => 'call_to_action')); if( $posts ): ?> &

我目前正试图从Wordpress中的自定义帖子类型返回一篇随机帖子。目前,它返回的所有内容都是在该自定义帖子类型中发布的最后一篇帖子。我目前正在使用此代码获取帖子:

<?php $posts = get_posts(array('posts_per_page' => 1, 'order_by' => 'rand', 'order' => 'ASC', 'post_type' => 'call_to_action')); if( $posts ): ?>
  <?php foreach ( $posts as $post ) : setup_postdata( $post ); ?>
    // Some code
  <?php endforeach; ?>
  <?php wp_reset_postdata(); ?>
<?php endif; ?>

//一些代码

'order\u by'=>'rand'
更改为
'orderby'=>'rand'

'order\u by'=>'rand'
更改为
'orderby'=>'rand'

啊,谢谢你的打字,但我还是得到了同样的结果。仅最新帖子。此CPTIf中您有多少帖子如果网站被缓存,即使您使用orderby=>rand,在清除缓存之前,您将看到相同的帖子。也许这就是问题所在。啊,谢谢你的打字错误,但我还是得到了同样的结果。仅最新帖子。此CPTIf中您有多少帖子如果网站被缓存,即使您使用orderby=>rand,在清除缓存之前,您将看到相同的帖子。也许这就是问题所在。