Ecommerce Shopify WordPress Discussion

Automatically add category to post for each user on wordpress site

Sorry for my English. I need your help, if anyone has the time. I would need code to add a category upon new user account and create it in the user's name. thanks a lot for your help I've searched a bit for information but it's beyond my skills. add_action('user_register', 'create_taxonomy_name_user'); function create_taxonomy_name_user( $user_id ) { }
Add the function in your active theme functions.php file. function create_term_from_username($user_id) { // Get the user data $user_info = get_userdata($user_id); //Change if you want term from any other user data $username = $user_info->user_login; //Define in which taxonomy we want to add term $taxonomy = 'category'; // Create a term based on the username $term_args = array( 'slug' => sanitize_title($username), // Sanitize the username to make it suitable for a term slug ); // Insert the term and get its ID $term_id = wp_insert_term($username, $taxonomy, $term_args); // Check if the term was created successfully if (is_wp_error($term_id)) { // Handle error if term creation fails error_log('Error creating term for user ' . $username . ': ' . $term_id->get_error_message()); } } add_action('user_register', 'create_term_from_username');

January 20, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.