php - 如何按字母顺序对转发器字段进行排序?ACF
问题描述
我想显示用户列表的名称并按用户名称的字母顺序排列它们。我怎样才能做到这一点?我正在寻求帮助来解决这个问题:
<?php if(get_field('sign_up', 'options')): ?>
<ul>
<?php while(has_sub_field('sign_up', 'options')): ?>
<li><?php the_sub_field('your_name', 'options'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
解决方案
尝试以下操作,使我们使用 array_multisort() 函数:
<?php // Get repeater value
$repeater = get_field('sign_up', 'options');
// Obtain list of columns
foreach ($repeater as $key => $row) {
$the_name[$key] = $row['your_name'];
}
// Sort the data by name column, ascending
array_multisort($the_name, SORT_ASC, $repeater);?>
<?php if($repeater): ?>
<ul>
<?php while(has_sub_field('sign_up', 'options')): ?>
<?php foreach( $repeater as $row ) { // Display newly orded columns ?>
<li><?php echo $row['your_name'];?></li>
<?php } ?>
<?php endwhile; ?>
</ul>
<?php endif;?>
推荐阅读
- python - 谷歌日历API位置python
- c - 使用 flex 和 bison 生成的编译器中的语法错误
- python-3.x - Python PIL 图像抓取崩溃
- swift - Swift 协议语法,其中 Self: 既是 UICollectionViewDataSource 又是 UICollectionViewDelegate
- c - Bash:通过 shell 变量将参数传递给 C 程序。如何处理空格和引号字符?
- ios - SwiftUI NavigationLink 从不释放内存
- python - 通过 Python 运行 SAS 代码以登录到特定的 SAS 数据库
- c# - 网络应用程序中的 Cookie 被删除
- swift - selectItem 时的集合视图布局错误(Swift 5)
- swift - 在 String 中创建 NSRange 时崩溃