• I am trying to update my term description using the wp_update_term function.
    When I run the code below, the meta data registered in the same term dissappears.

    $term_args = [
     'description' => 'text'
    ];
    $update_term = wp_update_term( $term_id, 'custom-term', $term_args );

    Do I have to get the meta data before this and register it after wp_update_term every time, or is there a way to avoid this?
    Thank you

    • This topic was modified 3 years, 11 months ago by Kai.
    • This topic was modified 3 years, 11 months ago by Kai.
    • This topic was modified 3 years, 11 months ago by Kai.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Are you sure that you are not mixing a taxonomy and the term slug?

    Thread Starter Kai

    (@kaiono)

    Thank you. I double checked again but the slug was not mixed up.
    I found out that the meta data dissapears when I saved an array object inside.

    Moderator bcworkz

    (@bcworkz)

    wp_update_term() doesn’t impact term meta one way or another on its own. However, to save term meta data, we typically hook into one of the function’s actions. I think the problem is in whatever logic is used to save term meta on creation. It’s not differentiating between a new insertion and an update. With an update, there’s no meta data, so what had been saved is replaced by empty data. So either alter that logic, or you will need to fetch the existing data before updating.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Term meta data deleted when using wp_update_term’ is closed to new replies.