高级自定义字段 foreach 以与 WordPress 相反的方向循环

Advanced Custom Fields foreach looping in opposite direction to WordPress

我一直在为这个绞尽脑汁。

背景:

以下代码有效,并且正在为相关 WordPress post.

抓取正确的分类术语信息

问题:

ACF 正在按照从新到旧的顺序输出术语。 WordPress 的 $game->name;正在按从旧到新的顺序输出术语。

这基本上意味着工具提示与来自 get_field('icon');

的图像不匹配
$games = get_the_terms(get_the_ID(), 'games')

foreach ($games as $game) {
    $term = array_pop($games);
    if ( get_field('icon', $term) ) {
        echo '<img src="' . get_field('icon', $term ) . '" alt="' . $game->name . '" data-placement="bottom" data-toggle="tooltip" title="' . $game->name . '" />';
    }
} 

到目前为止我已经尝试过:

非常感谢您的建议。

您似乎故意在代码中使用 array_pop??

只需使用 foreach 循环中的 $game 变量:

$games = get_the_terms(get_the_ID(), 'games')

foreach ($games as $game) {
    //$term = array_pop($games);
    if ( get_field('icon', $game) ) {
        echo '<img src="' . get_field('icon', $game ) . '" alt="' . $game->name . '" data-placement="bottom" data-toggle="tooltip" title="' . $game->name . '" />';
    }
}