将 ACF 添加到自定义函数

Add ACF to custom function

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

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

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

对于您的情况,您可以使用如下代码实现此目的

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