Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp group meta


  • sbdm05
    Participant

    @sbdm05

    Hello everyone!
    I would like to add a dropdown menu during the creation of groups.
    I have found this code that works perfectly:

    <?php
    /*
    Plugin Name: Favorite Color
    Plugin URI: http://MyWebsite.com
    Description: Let Groups Pick their favorite Color
    Version: 1.0
    Requires at least: 3.3
    Tested up to: 3.3.1
    License: GPL3
    Author: Your Name
    Author URI: http://YourCoolWebsite.com
    */
    function bp_group_meta_init() {
    function custom_field($meta_key='') {
    //get current group id and load meta_key value if passed. If not pass it blank
    return groups_get_groupmeta( bp_get_group_id(), $meta_key) ;
    }
    //code if using seperate files require( dirname( __FILE__ ) . '/buddypress-group-meta.php' );
    // This function is our custom field's form that is called in create a group and when editing group details
    function group_header_fields_markup() {
    global $bp, $wpdb;?>
    <label for="favorite-color">My Favorite Color</label>
    <input id="favorite-color" type="text" name="favorite-color" value="<?php echo custom_field('favorite-color'); ?>" />
    <br>
    <?php }
    // This saves the custom group meta – props to Boone for the function
    // Where $plain_fields = array.. you may add additional fields, eg
    //  $plain_fields = array(
    //      'field-one',
    //      'field-two'
    //  );
    function group_header_fields_save( $group_id ) {
    global $bp, $wpdb;
    $plain_fields = array(
    'favorite-color'
    );
    foreach( $plain_fields as $field ) {
    $key = $field;
    if ( isset( $_POST[$key] ) ) {
    $value = $_POST[$key];
    groups_update_groupmeta( $group_id, $field, $value );
    }
    }
    }
    add_filter( 'groups_custom_group_fields_editable', 'group_header_fields_markup' );
    add_action( 'groups_group_details_edited', 'group_header_fields_save' );
    add_action( 'groups_created_group',  'group_header_fields_save' );
     
    // Show the custom field in the group header
    function show_field_in_header( ) {
    echo "<p> My favorite color is:" . custom_field('favorite-color') . "</p>";
    }
    add_action('bp_group_header_meta' , 'show_field_in_header') ;
    }
    add_action( 'bp_include', 'bp_group_meta_init' );
    /* If you have code that does not need BuddyPress to run, then add it here. */
    ?>

    The only thing is that I dont know much about php, and I can’t seem to change the <input id=”favorite-color” type=”text” name=”favorite-color” value=”<?php echo custom_field(‘favorite-color’); ?>” /> into a drop down menu where the value would be sent.

    Could someone please give me some advice?

    Many thanks!

    So

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

  • leon71
    Participant

    @leon71

    Hi,
    I also have the same question I have managed to display a dropdown box.
    But now I’m looking for the solution to post and display the the ‘çountry’ value and display in the group header.

    [edited – please do not post large chunks of code. Use pastbin or gist and provide the url ]

    http://pastebin.com/5fLS2Q9m


    sbdm05
    Participant

    @sbdm05

    Hello Leon,
    This plugin would display the answer in the group header, might help:

    How to Edit Group Meta Tutorial


    leon71
    Participant

    @leon71

    I’ve fixed it and now everything works fine.
    Does anybody know how I can mark the field as ‘required’???

    [edited – please do not post large chunks of code. Use pastbin or gist and provide the url ]

    http://pastebin.com/UXtN5AJK


    leon71
    Participant

    @leon71

    Does anybody know how I can apply a validation rule to the ‘url’ field?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘bp group meta’ is closed to new replies.
Skip to toolbar