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 WordPress Web Developer, Front-end and 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.

Comments 2

Leave a Reply

Your email address will not be published. Required fields are marked *