I’m making an attempt to take away a string off of a bunch of slugs in phrases from a CPT taxonomy.
For instance, I’ve a time period named “Accounting” however the slug has the “accounting-expert-witnesses” I simply have to take away the “-expert-witnesses” a part of the slug.
I’m utilizing this put up as a reference because it seems to be what am I on the lookout for however I can’t appear to get any of the ideas to work: Methods to replace taxonomy customized subject with wp_update_term()?
I’ve tried utilizing update_term_meta, update_post_meta, wp_update_term and none of them are doing what I would like.
The closest I’ve bought is utilizing update_term_meta and it seems to be working once I error log the end result nevertheless once I have a look at the phrases within the dashboard nothing has been up to date.
I am unable to work out what I am doing mistaken right here?
operate remove_stuff() {
$phrases = get_terms( array(
'taxonomy' => 'experts_industries',
'hide_empty' => false,
) );
foreach($phrases as $time period) {
$newSlug = str_replace('-expert-witnesses', '' , $term->slug);
//update_term_meta($term->id, 'slug', $newSlug);
//update_post_meta($term->id, 'slug', $newSlug);
wp_update_term($term->id, 'experts_industries', array( 'slug' => $newSlug ));
error_log($term->slug);
}
}
add_action( 'wp_loaded', 'remove_stuff' );