Show ACF Custom Field Outside Loop

Glenn Glenn's Blog 2 Comments

This is how to display an Advanced Custom Field (ACF) outside of the WordPress Loop:-

<?php the_field('field_name','$post->ID');?>

Or to extend the code to only show if the field is present:-

<?php if(get_field('field_name','$post->ID'))
{
	echo '<p>' . get_field('field_name') . '</p>';
}
?>

In our tests we have found that ‘the_field’ and ‘get_field’ are interchangeable methods – the main thing is to ensure that you add ‘$post->ID’.

About the Author
Show ACF Custom Field Outside Loop Show ACF Custom Field Outside Loop 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced Web Designer / Web Developer (Webflow, WordPress, Weebly & Custom), Front-end / Back-end Developer & New Media Specialist, with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries, built up over a number of years.

  • Works if $post->ID is without quotes.

    ID );?>

  • Kausar

    shouldn’t the correct format be
    get_field(‘banner_background_image’,$post->ID)