Last active
October 2, 2019 18:29
-
-
Save stefanledin/44b20ddde3f8df8583c989412d184c49 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Register the custom taxonomy. | |
*/ | |
add_action( 'init', 'register_taxonomy_article_type' ); | |
function register_taxonomy_article_type() { | |
register_taxonomy( 'article_type', 'post', array( | |
'label' => 'Article type', | |
'hierarchical' => true, | |
// This taxonomy should only be visible in the admin menu. | |
'public' => false, | |
'show_ui' => true, | |
'meta_box_cb' => false, | |
) ); | |
} | |
/** | |
* Populate the ACF field with terms from the custom taxonomy Article type. | |
*/ | |
add_filter( 'acf/load_field/name=article_type', function( $field ) { | |
// Get all taxonomy terms | |
$article_types = get_terms( array( | |
'taxonomy' => 'article_type', | |
'hide_empty' => false | |
) ); | |
// Add each term to the choices array. | |
// Example: $field['choices']['review'] = Review | |
foreach ( $article_types as $type ) { | |
$field['choices'][$type->slug] = $type->name; | |
} | |
return $field; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice. how to sync it with taxonomy to update it based on acf select field?