Created
August 2, 2022 07:27
-
-
Save odil-io/2fa9cd04bcdf2565e1f3eebee5540e94 to your computer and use it in GitHub Desktop.
ACF: Populate select-field with Taxonomy names
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 | |
/** | |
* List Taxonomies connected to Post Type in a Select Field type | |
* | |
* @param Array $field Field settings. | |
* @return void | |
*/ | |
function namespace_get_taxonomy_list( $field ) { | |
$field['choices'] = array(); | |
$taxonomies = get_object_taxonomies( 'POST_TYPE', 'objects' ); | |
foreach ( $taxonomies as $taxonomy ) : | |
$choices[ $taxonomy->name ] = $taxonomy->label; | |
endforeach; | |
$field['choices'] = $choices; | |
return $field; | |
} | |
add_filter( 'acf/load_field/key=field_id', 'namespace_get_taxonomy_list' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment