Home › Forums › ACF PRO › Question set Global variable ACF › Reply To: Question set Global variable ACF
If you haven’t already I would set the options page to autoload. http://www.advancedcustomfields.com/resources/acf_add_options_page/ This causes WP to cache the values so that extra DB calls are not needed to get them, just in case that’s your concern.
As far as opinion on using a global variable. Global variables, in my opinion, should only be used when there isn’t a better way to do it.
I personally don’t see much difference between the following.
// ACF get_field()
$value = get_field('gallery_wedding','option');
// using a global variable
global $weddingopt;
$value = $weddingopt['gallery_wedding'];
Of the two I would use the first. Why, because at does not depend on a global variable and because it does not create a dependency and require editing the function that creates the global variable every time I add a new field. The global variable option simply increases the work and over-complicates the theme without adding much in the way of a benefit over just using the ACF function where you need the value.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.