Last active
December 30, 2024 01:20
-
-
Save 8ctopotamus/160a25a78cb83023b365a68344ff72fb to your computer and use it in GitHub Desktop.
get acf fields by fieldgroup slug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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