Skip to content

Instantly share code, notes, and snippets.

@odil-io
Created August 2, 2022 07:27
Show Gist options
  • Save odil-io/2fa9cd04bcdf2565e1f3eebee5540e94 to your computer and use it in GitHub Desktop.
Save odil-io/2fa9cd04bcdf2565e1f3eebee5540e94 to your computer and use it in GitHub Desktop.
ACF: Populate select-field with Taxonomy names
<?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