php - 返回每个帖子的元数组并合并为一个
问题描述
我有一个名为 Boutique 的自定义帖子类型,其中包含一个名为 Products 的转发器字段。
我的循环正在工作,但我希望所有产品都以随机顺序显示。
例子:
精品 A 与产品 : [1,2,3] 精品 B 与产品 : [4,5,6]
我想要一个这样的数组:array([1],[4],[2],[3],[5],[6])
实际上我只能通过随机播放来获得这个:数组([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; ?>
解决方案
推荐阅读
- sql - 如何从返回多个重复记录的查询中选择唯一行?
- python - scipy.stats cdf 大于 1
- r - case_when 在多个条件下中断
- python-3.x - python3:如何将代码直接粘贴到调用函数的控制台中,而不必加载 .py 文件?
- cloud-foundry - PCF Config Server 定期刷新配置?
- python - 如何在列表末尾获取某些值,每隔一段时间获取这些值,并在 Python 中的原始列表中插入某些位置?
- flutter - 我使用flutter_modular,我需要动态创建自定义转换。我怎么能做到这一点?
- javascript - 使用 darge-d3 的可折叠力布局
- java - Java - 将一个元素添加到不可变列表
- postgresql - 如何根据查询结果退出 psql