Skip to:
Content
Pages
Categories
Search
Top
Bottom

Group Extension API – multiple fields?

  • @timrourke

    Participant

    Hi!

    I’m trying to figure out how to use the Group Extension API to register multiple custom fields, and display/edit them under the same group view.

    My use case involves allowing a group to define their address. This means that I’ll need to register fields like:

    -Address
    -Unit/apt/ste number
    -City
    -State
    -Zip

    I’d like to be able to display/edit these elements under the same view, as well.

    What is the correct syntax for registering these elements? It is clear that I cannot have 2 separate __construct(); defines, like this:

    function __construct() {
            $args = array(
                'slug' => 'group-extension-zipcode',
                'name' => 'Group Information',
                'nav_item_position' => 105,
                'screens' => array(
                    'edit' => array(
                        'name' => 'Details',
                        // Changes the text of the Submit button
                        // on the Edit page
                        'submit_text' => 'Submit',
                    ),
                    'create' => array(
                        'position' => 100,
                    ),
                ),
            );
            parent::init( $args );
        }
    
        function __construct() {
            $args = array(
                'slug' => 'group-extension-address',
                'name' => 'Group Information',
                'nav_item_position' => 105,
                'screens' => array(
                    'edit' => array(
                        'name' => 'Details',
                        // Changes the text of the Submit button
                        // on the Edit page
                        'submit_text' => 'Submit',
                    ),
                    'create' => array(
                        'position' => 100,
                    ),
                ),
            );
            parent::init( $
        }

    Does this mean that I need to register separate classes to define multiple fields? If so, how do I associate the fields to exist under the same view/edit screen?

    I’m totally crap at PHP and am probably just overlooking simple multidimensional constructor syntax for parent::init( $args );?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • @shanebp

    Moderator

    You want to add these fields are part of the group creation process, yes?

    If so, you don’t need the Group Extension API.
    Use this hook instead groups_custom_group_fields_editable.

    function tim_custom_group_field() {
       echo ' put your fields here';
    }
    add_action( 'groups_custom_group_fields_editable', 'tim_custom_group_field' );

    Then use this hook to save the field groups_create_group_step_save_group-details
    Then get the data with groups_get_groupmeta

    @timrourke

    Participant

    shanebp, you’re awesome! This is incredibly helpful stuff. I’ll start looking into this right away.

    Would this group metadata then be searchable, as well? This is extremely important for my use case. If not, any thoughts on how to include this metadata in group search results?

    Thanks again! Cheers,

    Tim

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Group Extension API – multiple fields?’ is closed to new replies.
Skip to toolbar