首页 文章

如何使用ACF插件显示分类法术语自定义字段值

提问于
浏览
-2

我使用了Advance Custom Field(ACF)wordpress插件在Woocommerce - > Product - > Categories表单中添加自定义文件 .

现在我无法在类别页面上打印该字段值 .

请参阅此屏幕截图以了解字段slug名称和其他详细信息 - > http://nimb.ws/BsSiJO并帮助我在类别页面上显示该字段值 .

谢谢,Ketan .

1 回答

  • 0

    Display a field

    <p><?php the_field('field_name', $term); ?></p>
    

    Retrieve a field

    <?php
    
    $variable = get_field('field_name', 'product-cat_23');
    
    // do something with $variable
    
    ?>
    

    Finding the term related to the current post

    <?php
    
    // load all 'category' terms for the post
    $terms = get_the_terms( get_the_ID(), 'category');
    
    
    // we will use the first term to load ACF data from
    if( !empty($terms) ) {
    
        $term = array_pop($terms);
    
        $custom_field = get_field('category_image', $term );
    
        // do something with $custom_field
    }
    
    ?>
    

相关问题