【问题标题】:ACF Fields are not showing up on HomepageACF 字段未显示在主页上
【发布时间】:2020-11-26 18:23:06
【问题描述】:

我想自定义 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;
}

同样,如果我打印包含所有字段的 Array Yith Setting Page 打印数组。

在主页上只返回了几个字段!

我不知道这是 Array 还是 ACF 的问题,请帮我解决这个问题,这是我的代码。

【问题讨论】:

  • 请不要包含代码图像,您的问题应该包含代码块中格式化的代码本身。
  • 我在底部添加了代码。有必要使用屏幕截图详细说明我的问题。
  • 我已将代码 sn-p 移至顶部。

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


【解决方案1】:

我通过更改 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>
.
.
.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-06
    • 2021-11-26
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    相关资源
    最近更新 更多