返回每个帖子的元数组并合并为一个

时间:2019-02-08 21:56:44

标签: php wordpress

我有一个称为“精品店”的自定义帖子类型,其中一个名为“产品”的转发器字段。

我的循环正在工作,但我希望所有产品以随机顺序显示。

示例:

精品A与产品:[1,2,3] 精品店B的产品:[4,5,6]

我想要一个这样的数组:array([1],[4],[2],[3],[5],[6])

实际上,我只能使用shuffle来获取它:array([4,5,6],[1,2,3])

我应该如何将所有产品合并到一个阵列中,这样我才能随机播放并执行循环?

$boutiques = get_posts(array(
    'fields'          => 'ids',
    'posts_per_page'  => -1,
    'post_type' => 'boutique'
));
shuffle($boutiques);

 foreach ( $boutiques as $boutique_id ) {

          if( have_rows('boutique_products', $boutique_id) ):
      while  ( have_rows('boutique_products', $boutique_id) ): 
        the_row(); ?>

        <div class="boutique_product">
          <a href="<?php 
   echo esc_url( $boutique_url ); ?>">
            <img src="<?php 
   the_sub_field('product_img'); ?>">
          </a>
        </div>

      <?php  
   endwhile; else :
  endif; ?>

0 个答案:

没有答案