Skip to content

Instantly share code, notes, and snippets.

@8ctopotamus
Last active December 30, 2024 01:20
Show Gist options
  • Save 8ctopotamus/160a25a78cb83023b365a68344ff72fb to your computer and use it in GitHub Desktop.
Save 8ctopotamus/160a25a78cb83023b365a68344ff72fb to your computer and use it in GitHub Desktop.
get acf fields by fieldgroup slug
<?php
// Note: [ACF Local JSON Sync](https://www.advancedcustomfields.com/resources/local-json/) must be set up for this strategy.
// Otherwise, just tweak the logic for detecting the field_group.
function _get_acf_fields_by_fieldgroup_slug( $slug ) {
if ( !$slug ) return null;
$acf_field_groups = acf_get_field_groups();
$fields = [];
foreach( $acf_field_groups as $group ) {
if ( str_contains( $group['local_file'], $slug ) ) {
$fields = acf_get_fields($group['ID']);
break;
}
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment