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. 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.