Home Forums Front-end Issues get_field in field filter cause infinite loop Reply To: get_field in field filter cause infinite loop

  • I’ve found that, as you say, it’s just the way it is. I discovered this when creating plugins that use ACF. Especially when getting a field that was attached to the same location as the field I was trying to dynamically generate. Caused quite a bit of forehead to screen action at the time.

    There is probably something that can be done about it. You could probably remove all of the filters and actions that are causing the infinite loop before you call get_field() and then add them again after you call get_field(). But this seems like a lot more work than using get_post_meta().

    You may also be able to do other things to stop it. Maybe create a check at the beginning of your function to make sure that you’re not doing your own action twice. I haven’t tried this. For me it was again just simpler to use get_post_meta

    Now when I’m creating a filter or action for ACF I just don’t use ACF functions because there is always the chance of creating the infinite loop when you do.

    Actually, these same types of infinite loops can be created in WP as well. For example, if you create a filter on the WP hook 'get_post_metadata' and then in that filter you call the function get_post_meta(), unless you do a few back flips to prevent it you set up an infinite loop situation.