Search code examples
phpfunctionadvanced-custom-fields

Add ACF to custom function


I need to add my ACF field to a custom function. I have tried this but there is syntax error.

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

Solution

  • When you are calling the_field('designer') outside the actual post loop, you need to pass the post ID as well. Here is the Ref.

    For your case, you can achieve this by using the code like below

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