在同一页面上镜像Wordpress随机查询

在同一页面上镜像Wordpress随机查询,wordpress,Wordpress,我使用wordpress查询从自定义帖子类型中随机显示3篇帖子。我使用的代码如下,运行良好: <?php $my_query = new WP_Query('post_type=my_post_type&orderby=rand&showposts=3'); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> Do Stuff <?php endwh

我使用wordpress查询从自定义帖子类型中随机显示3篇帖子。我使用的代码如下,运行良好:

<?php $my_query = new WP_Query('post_type=my_post_type&orderby=rand&showposts=3'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

Do Stuff

<?php endwhile; ?>
<?wp_reset_query(); ?>

做事
但是,我想镜像下面的相同查询,以再次显示相同的项目。因此,在一个页面上有两个wordpress查询,第一个查询挑选3篇随机文章,第二个查询显示与第一个查询完全相同的结果。任何帮助都将不胜感激。谢谢

试试这个:)


做事


在循环中,您可能可以将其保存为$myPostVar.=“Content”;如果您想指定不同的内容格式,您甚至可以将所有内容都放在数组中,以便稍后显示。嗨,Robert,我对此一无所知,您知道包括当前使用的php在内的完整代码是什么吗?谢谢你,罗伯特,太好了!
<?php $my_query = new WP_Query('post_type=post&orderby=rand&showposts=3'); ?>
<?php $i=0; ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

Do Stuff

<?php
    $myPostVar[$i] = array (
            'title'     => get_the_title(),
            'content'   => get_the_content()
    );
    $i++;
?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

<?php foreach ($myPostVar as $Postvar) : ?>
    <h2><?php echo $Postvar['title']; ?></h2>
    <p><?php echo $Postvar['content']; ?></p>
<?php endforeach; ?>