use App\Models\Category; // Get the category to update $category = Category::find(1); // Update the category name $category->name = "New Category Name"; $category->save();
// Get the category ID to update $category_id = 5; // Update the category name $updated = wp_update_term( $category_id, 'category', array( 'name' => 'New Category Name' ) ); if (is_wp_error($updated)) { // Handle the update error } else { // Category updated successfully }This code updates the name of the category with an ID of 5 to "New Category Name" using the `wp_update_term` function, which is a part of the WordPress core. Package library: WordPress Core Functions