Add term to taxonomy programatically

admin2025-06-05  1

I have a 1000+ terms I need to add to a taxonomy called county. I am trying to use this function wp_insert_term but the term is not being added to the database. I am running this code inside function.php as a test before looping over each unique term. Should I be using a specific hook?

wp_insert_term(
  'Maricopa',
  'county',
  array(
    'description'=> 'Maricopa',
    'slug' => 'maricopa'
  )
);

Also curious of other ways of adding multiple terms at once. Is there a REST API option for doing this?

EDIT

Tried using this hook but same result the term was not added to the 'county' taxonomy.

function add_county_terms() {
  wp_insert_term( 'Maricopa', 'county', array(
    'slug' => 'maricopa',
  ));
}
add_action( 'wp_loaded', 'add_county_terms' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749133036a316640.html

最新回复(0)