WooCommerce类别和ACF

时间:2015-04-09 19:18:28

标签: wordpress woocommerce advanced-custom-fields

我正在使用Advanced Custom Fields(ACF)插件。在WooCommerce产品类别中,我想要一个seo的内容区域。 ACF会帮助我但不起作用,因为网站的前端没有显示任何内容。

content-product.php有额外的字段:

<li <?php post_class(); ?> style="max-width:<?php echo $column_width; ?>px">
    <div class="mk-product-holder">
    <?php do_action( 'woocommerce_before_shop_loop_item' ); ?>

        <div class="mk-love-holder">
        <?php if( function_exists('mk_love_this') ) mk_love_this();      ?>
        </div>

        <h3><a href="<?php echo get_permalink();?>"><?php the_title(); ?></a>

        // Here is the extrafield SEO-text, the field is registered in fields with name "extratext"
        <?php echo get_field('extratext'); ?>       

        </h3>
    </div>
</li>

WooCommerce类别屏幕截图: http://www.directupload.net/file/d/3952/kzb8dcjk_png.htm

1 个答案:

答案 0 :(得分:5)

您尚未为$postId函数设置get_field()参数,因此它默认为当前帖子对象(可能是该类别中的第一个帖子)。

有关如何从其他地方获取字段的说明,请参阅documentation中的从其他地方获取值部分。

所以你要写这样的东西:

<?php
$queriedObject=get_queried_object();
echo get_field('extratext','product_cat_'.$queriedObject->term_id);
?>
相关问题