Add location field to buddy press group in wordpress website

390 views Asked by At

Is there a way to add location field to buddy press group in wordpress. And later able to search group based on location.

1

There are 1 answers

3
Domain On

Below code can be used for adding location field in group edit screen in backend, Put this code in theme functions.php or any plugin:-

add_action('bp_groups_admin_meta_boxes','wdm_groups_custom_group_fields_editable');
function wdm_groups_custom_group_fields_editable(){ 

add_meta_box( 'wdm_location', 'Location', 'wdm_bp_groups_location', get_current_screen()->id, 'normal', 'core' );
}

function wdm_bp_groups_location($item){
    $group_id = $item->id;

     $location = groups_get_groupmeta($group_id, 'wdm_location', true);


    ?>
<select name='wdm_location'>
    <option <?php echo ($location == 'india') ? 'selected' : ''; ?>>India</option>
    <option <?php echo ($location == 'US') ? 'selected' : ''; ?>>US</option>
</select>
<?php }

add_action('bp_groups_admin_load','wdm_bp_groups_admin_load');
function wdm_bp_groups_admin_load($temp){

    if(isset($_POST['wdm_location']) && $_POST['wdm_location']){
         groups_update_groupmeta($_REQUEST['gid'], 'wdm_location', $_POST['wdm_location']);
    }
}