Skip to content

Instantly share code, notes, and snippets.

@interactiveRob
Created November 5, 2018 20:45
Show Gist options
  • Select an option

  • Save interactiveRob/b7f2d0d768ba907c486b267d93ef010b to your computer and use it in GitHub Desktop.

Select an option

Save interactiveRob/b7f2d0d768ba907c486b267d93ef010b to your computer and use it in GitHub Desktop.
Check if ACF group has content
function acf_group_has_content($group){
/* Necessarily checks if a groups sub_fields have content
because the ACF group always returns true even when the
group is empty */
foreach ($group as $item):
if($item):
return true;
endif;
endforeach;
}
@interactiveRob
Copy link
Author

interactiveRob commented Nov 5, 2018

Example usage
$my_acf_group = get_field('my_acf_group');

if( acf_group_has_content($my_acf_group) ):
//do something
endif;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment