0

I'm trying to import some terms for custom taxonomies. Those terms have custom fields(added with ACF). I know I can insert terms with:

wp_insert_term( $term, $taxonomy, $args = array() );

I can't add values for the custom fields though.

Is there some way I can add custom fields to this function? Or use CSV somehow?

Thanks!

codewario
  • 19,553
  • 20
  • 90
  • 159
Luc
  • 1,765
  • 5
  • 24
  • 44

1 Answers1

1

When using wp_insert_term it will return you an array with the Id and the term (https://codex.wordpress.org/Function_Reference/wp_insert_term#Return_Values)

Then you just have to use add_term_meta (https://codex.wordpress.org/Function_Reference/add_term_meta)

Example :

$term = wp_insert_term('red', 'colour');
add_term_meta($term['term_id'], 'rgba', '#FF0000');
Ianis
  • 1,165
  • 6
  • 12