A terms slug is not stored as meta/custom fields, and it’s definitely not post meta, so update_term_meta
and update_post_meta
are innapropriate and can never be used to achieve your goal.
The correct function is wp_update_term
, however you’ve used that incorrectly too:
$term->id
isn’t a thing, if we look at theWP_Term
class and the examples on the official docs, we see$term->term_id
is what should be used- there is no code checking the return value of
wp_update_term
, if it failed there would have been aWP_Error
object with an error message explaining what happened. error_log($term->slug);
doesn’t fetch the new slug from the database or make a new query to check for a new slug, this cannot be used to test if it worked. You need to check the return value ofwp_update_term
instead
From the official dev docs:
Return
(array|WP_Error) An array containing the term_id and term_taxonomy_id, WP_Error otherwise.
More examples and information at: