Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Page that Filters Groups


  • Nick Watson
    Participant

    @nickbwatson

    So I’ve created a plugin that allows the admin to change a group to be a “Featured” group through 2 radio buttons (featured and not featured)

    It’s working great on the group page I have it set so that it will display an image if the group is featured / not featured.

    MY QUESTION, is as follows:

    I have a custom page that I would like to use the group-loop (i’ll make a custom loop) that filters out all groups that have the featured radio button set to “not featured”.

    I was thinking just having an if statement, but that doesn’t seem to be working (or I just have no idea what to put).

    Something along the lines of

    <?php if ( bp_featured_group == "featured") : ?>

    I know the code is very wrong but I am new to php and I wanted a bit of help.

    Thanks

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

  • Peter Anselmo
    Participant

    @peteranselmo

    What specifically is stored when a group is marked as “featured”? Do you give your radio buttons a value attribute? How are you storing it (is the actual variable name $bp_featured_group?).


    Nick Watson
    Participant

    @nickbwatson

    function bp_featured_group_form() {
    if ( is_site_admin ) {
    ?>
    <hr />
    <div class="radio">
    <label><input type="radio" name="bp_featured_group" value="normal" <?php bp_featured_group_setting('normal') ?> /> <?php _e( 'This is just a normal group', 'featured_group' ) ?></label>
    <label><input type="radio" name="bp_featured_group" value="Featured" <?php bp_featured_group_setting('Featured') ?> /> <?php _e( 'This is a featured group', 'featured_group' ) ?></label>
    </div>
    <hr />
    <?php
    }
    }
    add_action ( 'bp_after_group_settings_admin' ,'bp_featured_group_form' );
    add_action ( 'bp_after_group_settings_creation_step' ,'bp_featured_group_form' );

    function bp_featured_group() {
    if (bp_get_featured_group()) {
    echo bp_get_featured_group();
    }
    }

    // Get the official title group setting
    function bp_get_featured_group( $group = false ) {
    global $groups_template;
    if ( !$group )
    $group =& $groups_template->group;
    $featured_group = groups_get_groupmeta( $group->id, 'bp_featured_group' );
    return apply_filters( 'bp_featured_group', $featured_group );
    }

    // echo official title group checked setting for the group admin - default to 'normal' in group creation
    function bp_featured_group_setting( $setting ) {
    if ( $setting == bp_get_featured_group() )
    echo ' checked="checked"';
    if ( !bp_get_featured_group() && $setting == 'normal' )
    echo ' checked="checked"';
    }

    // Save the official_title group setting in the group meta, if normal, delete it
    function bp_save_featured_group( $group_id ) {
    global $bp, $_POST;
    if ( $postval = $_POST['bp_featured_group'] ) {
    if ( $postval == 'Featured' )
    groups_update_groupmeta( $group_id->id, 'bp_featured_group', $postval );
    elseif ( $postval=='normal' )
    groups_delete_groupmeta( $group_id->id, 'bp_featured_group' );
    }
    }
    add_action( 'groups_group_after_save', 'bp_save_featured_group' );

    I may as well post the code,

    Here it is.

    Thanks


    Nick Watson
    Participant

    @nickbwatson

    I really just need help with the if statement.

    Thanks


    Peter Anselmo
    Participant

    @peteranselmo

    It seems like you should use the bp_get_featured_group() function in your if statement, as it returns the value rather than echoing it.

    Maybe something like this?

    <?php if ( bp_get_featured_group() == "featured") : ?>

    I’m not totally sure, You might have to insert some “echos” in there and debug along the way.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Page that Filters Groups’ is closed to new replies.
Skip to toolbar