将 ACF 添加到自定义函数

时间:2021-04-30 05:10:19

标签: php function advanced-custom-fields

我需要将我的 ACF 字段添加到自定义函数中。我试过了,但有语法错误。

add_action( 'flatsome_custom_single_product_1', function () {
    echo <?php the_field('designer'); ?>;
} );

1 个答案:

答案 0 :(得分:0)

当您在实际帖子循环之外调用 the_field('designer') 时,您还需要传递帖子 ID。 这是Ref

对于您的情况,您可以使用如下代码来实现这一点

add_action( 'flatsome_custom_single_product_1', function () {
global $post;
echo  get_field('designer', $post->ID);
} );