Skip to:
Content
Pages
Categories
Search
Top
Bottom

cannot create group programmatically


  • meitalaaa
    Participant

    @meitalaaa

    I wrote the following function, but i still can’t create a group. I’ve made sure that the function is getting called, so that is not the issue

    function start_a_new_group($profile_id, $status) {
    if ( !function_exists( ‘groups_create_group’ ) ) {
    require_once ‘/bp-groups/bp-groups-functions.php’;
    }

    $defaults = array(
    ‘group_id’ => $profile_id,
    ‘creator_id’ => get_current_user_id(),
    ‘name’ => ”,
    ‘description’ => ”,
    ‘slug’ => ”,
    ‘status’ => $status,
    ‘enable_forum’ => 0,
    ‘date_created’ => bp_core_current_time()
    );
    return groups_create_group($defaults);
    }

    Wordpress version 5.8.2
    Buddypress verion 9.1.1
    Theme is Twenty Twenty

    Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp
    Moderator

    @shanebp

    For a new group, leave group_id empty.


    meitalaaa
    Participant

    @meitalaaa

    $defaults = array(
    ‘group_id’ => null,
    ‘creator_id’ => get_current_user_id(),
    ‘name’ => ”,
    ‘description’ => ”,
    ‘slug’ => ”,
    ‘status’ => $status,
    ‘enable_forum’ => 0,
    ‘date_created’ => bp_core_current_time()
    );

    Like this? I’ve changed it, but it’s still not creating the group.


    shanebp
    Moderator

    @shanebp

    Please use the code button when posting code.
    If you are calling the function before BuddyPress has completely loaded, then it will not work.
    Your function_exists check won’t work even if you include that file. That file contains functions that rely on the loading of the full groups component.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar