Home Forums Backend Issues (wp-admin) Using fields outside the loop


Using fields outside the loop

  • Hi Elliott,

    First, thanks for the plugin! It really does open up a world of possibility.

    My question: Can I use ACF’s built-in functions outside the loop? It seems as though I can’t – if I just drop a print_r(get_fields() ); into functions.php, I only get an array of empty key fields back – but I may be doing something wrong.

  • Hi @squarestarmedia

    Currently, the ACF functions can not be used in the root of the functions.php file.
    You need to use an action on or later than ‘init’ to get the ACF functions to work.

    As for the get_fields function, there is a parameter to specify a post_id. Use this to target the post to load the values from.


  • Thanks Elliot – I was just coming back to explain that I forgot to add the post_id to my example, but obviously it doesn’t affect the info from your first paragraph.

    I have got a system working now, but maybe you could clarify something for me: Because of WP’s use of hooks (like in this case), if you want to work with variables between hooked functions, you basically have to assign them to global variables – is that correct, or is there a better way?


  • Hi @squarestarmedia

    Pretty much, yes. But there is always more than one way to skin a cat!


  • Hi Elliot, would you mind showing how the action on or later than โ€˜initโ€™ approach would look like. I have a similar issue where I’m I’m using ACF in the function.php file and using cron jobs to trigger the function..


  • This reply has been marked as private.
Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Using fields outside the loop’ is closed to new replies.