ACF字段未显示在主页上

时间:2020-08-06 13:15:37

标签: php wordpress plugins advanced-custom-fields acfpro

我想自定义Yith插件,我想为其添加一些具有现有字段的自定义字段。我正在从ACF中获取字段,并将它们添加到数组中。ACF字段在Yith Setting中显示,但是在首页和其他网站页面中仅显示少数字段。

add_filter('yith_woocompare_standard_fields_array','ta_yith_woo_compare');
function ta_yith_woo_compare($fields){      
    $acf_fields_groups = acf_get_fields(5258);
    $labels = array();
    foreach($acf_fields_groups as $grp)
    {
        $group_id = $grp['ID'];
        $sub_fields = $grp['sub_fields'];
        foreach($sub_fields as $fld){
            $labels[$fld['name']] = $fld['label'];
        }
    }

    $fields =$fields + $labels;
    return $fields;
}

类似地,如果我打印所有字段的数组Yith设置页打印数组。 enter image description here

在首页上只返回了几个字段! enter image description here

我不知道这是Array或ACF的问题,请帮助我解决此问题,这是我的代码。

1 个答案:

答案 0 :(得分:0)

我通过更改Yith插件中compare.php中的以下代码来解决这个问题。

<?php foreach ($fields as $field => $name) : ?>
<th>
    <?php if ($field != 'image') echo esc_html( $name); ?>
</th>
.
.
.

更改为此=>

<?php foreach ($fields as $field => $name) : ?>
<th>
    <?php if ($field != 'image') echo esc_html( $field ); ?>
</th>
.
.
.
相关问题