I’m not sure why you’re seeing the ID increment, however one problem is that your function call to get_terms()
needs to include an array of taxonomy names as the first parameter.
In your case, you just need to include an array with a single taxonomy name. For example:
$existing_terms = get_terms(array('custom_taxonomy'), array(
'hide_empty' => false
)
);
When I ran your sample (without this array) I was getting an error response from the get_terms()
function.
Adding this array seemed to work as you described. More information on how to use get_terms()
.