I want add some custom field when i create new grup, (I used for countdown) but it does not work when create new group, it only works when edit groups.
And I have this code :
function save_custom_buddypress_group_textinput($group_id) {
if ( isset($_POST['custom_group_textinput']) ) {
if ( $group_id == 0 ) {
$group_id = buddypress()->groups->new_group_id;
}elseif(bp_get_current_group_id() > 0) {
$group_id = bp_get_current_group_id();
}
$text_input_value = sanitize_text_field($_POST['custom_group_textinput']);
groups_update_groupmeta($group_id, 'custom_group_textinput', $text_input_value);
}
}
add_action('groups_group_after_save', 'save_custom_buddypress_group_textinput');
add_action('groups_group_create_complete', 'save_custom_buddypress_group_textinput');
add_action('groups_group_edit_save_complete', 'save_custom_buddypress_group_textinput');```
my code is designed to save custom fields in BuddyPress groups when a group is created or edited. However, i mentioned that it's not working when creating a new group.
$group_id become 0 and not working
This is my final code: