The wp_ajax_
is a prefix for your ajax action. your action is my_tag_count
so its should be:
add_action( 'wp_ajax_my_tag_count', 'my_action' );
You tried to access the wrong url in the ajax request because you set
wp_localize_script( 'custom', 'my_ajax_obj', $ajax_url );
So the the request url should be my_ajax_obj
its not an object its don’t have ajax_url
in it. So in the request url use only my_ajax_obj
.
Another things
Add to the get_user_meta
3rd args to true to get single value instead of array.
$test1 = get_user_meta( $user_id, 'custom_meta', true );
And you don’t need to initialze the use meta update will update if exist and if not its will add. so you only need this.
$user_id = get_current_user_id();
$um_val = sanitize_text_field( $_POST['custom_meta'] );
update_user_meta( $user_id, 'custom_meta', $um_val );