Skip to main content
added 508 characters in body
Source Link

I am trying to remove a string off of a bunch of slugs in terms from a CPT taxonomy slugs that were added and.

For example, I have a term named "Accounting" but the slug has the "accounting-expert-witnesses" I just need to get removedremove the "-expert-witnesses" part of the slug.

I'm tryingI am using this post as a reference as it appears to usebe what am I looking for but I cannot seem to get any of the suggestions to work: How to update taxonomy custom field with wp_update_term()?

I have tried using update_term_meta, update_post_meta, wp_update_term and none of them are doing what I need.

The closest I've got is using update_term_meta and it appears to be working when I error log the result however it does not appear to have worked when I viewlook at the terms throughin the dashboard? nothing has been updated.

I can't figure out what I'm doing wrong here?

    function remove_stuff() {
    $terms = get_terms( array(
        'taxonomy' => 'experts_industries',
        'hide_empty' => false,
    ) );

    foreach($terms as $term) {

        update_term_meta($term->id, 'experts_industries', array('slug'$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' );

BTW: I'm not worried about the wp_loaded action, I'm doing everything locally and then removing this code. Unless that's the problem...?

I am trying to remove a string off of a bunch of CPT taxonomy slugs that were added and need to get removed.

I'm trying to use update_term_meta and it appears to be working when I error log the result however it does not appear to have worked when I view the terms through the dashboard?

I can't figure out what I'm doing wrong here?

function remove_stuff() {
    $terms = get_terms( array(
        'taxonomy' => 'experts_industries',
        'hide_empty' => false,
    ) );

    foreach($terms as $term) {

        update_term_meta($term->id, 'experts_industries', array('slug' => str_replace('-expert-witnesses', '' , $term->slug) ));

        error_log($term->slug);

    }
}
 
add_action( 'wp_loaded', 'remove_stuff' );

BTW: I'm not worried about the wp_loaded action, I'm doing everything locally and then removing this code. Unless that's the problem...?

I am trying to remove a string off of a bunch of slugs in terms from a CPT taxonomy.

For example, I have a term named "Accounting" but the slug has the "accounting-expert-witnesses" I just need to remove the "-expert-witnesses" part of the slug.

I am using this post as a reference as it appears to be what am I looking for but I cannot seem to get any of the suggestions to work: How to update taxonomy custom field with wp_update_term()?

I have tried using update_term_meta, update_post_meta, wp_update_term and none of them are doing what I need.

The closest I've got is using update_term_meta and it appears to be working when I error log the result however when I look at the terms in the dashboard nothing has been updated.

I can't figure out what I'm doing wrong here?

    function remove_stuff() {
    $terms = get_terms( array(
        'taxonomy' => 'experts_industries',
        'hide_empty' => false,
    ) );

    foreach($terms as $term) {

        $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' );
Source Link

update_term_meta not working

I am trying to remove a string off of a bunch of CPT taxonomy slugs that were added and need to get removed.

I'm trying to use update_term_meta and it appears to be working when I error log the result however it does not appear to have worked when I view the terms through the dashboard?

I can't figure out what I'm doing wrong here?

function remove_stuff() {
    $terms = get_terms( array(
        'taxonomy' => 'experts_industries',
        'hide_empty' => false,
    ) );

    foreach($terms as $term) {

        update_term_meta($term->id, 'experts_industries', array('slug' => str_replace('-expert-witnesses', '' , $term->slug) ));

        error_log($term->slug);

    }
}

add_action( 'wp_loaded', 'remove_stuff' );

BTW: I'm not worried about the wp_loaded action, I'm doing everything locally and then removing this code. Unless that's the problem...?