Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Member Directory sub-directories using $bp->current_action?


  • buddypresser
    Participant

    @buddypresser

    Hey guys,

    Using BP 1.1.2 and latest WPMU… and really stuck!

    I’m working on a site and I need the Members directory to be sortable not by A-Z, but by newest members, recently active, etc.

    I’ve been playing around for days with the AJAX calls but can’t make this one work.

    I tried using $_GET and $_POST to send the listing type, then picking that up and inserting it into the function like this: bp_has_site_members( ‘type=’ . $type )

    and it worked – for the first page of results. But as soon as you click an AJAX page nav button, to view more members, it loses the GET variable and reverts to the default listing.

    So I’m going to hardcore it into custom Members loops, with ‘type=XYZ’ in the bp_has_site_members() function on each.

    I guess that means having /directories/members/newest/ and /directories/members/active/, which is fine with me if it’s the best way.

    Here’s where I get lost…

    I know that with the URL mysite.com/members/newest/, or /members/active/, I could set the $bp->current_action to ‘newest’ or ‘active’, but I can’t work out how to write a function that, when those URLs are accessed, sends users to the relevant template!

    I’ve searched all through the core but this one has me stumped.

    Any advice?

    Thanks!

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

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    The reason the type wasn’t passing in the ajax was because it wasn’t saved anywhere in the loop form… You could try replacing the “bp_the_site_member_hidden_fields” function with this in bp-custom.php, then calling this function in members-loop.php in its place…

    function bp_custom_the_site_member_hidden_fields() {
    if ( isset( $_REQUEST['s'] ) ) {
    echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
    }

    if ( isset( $_REQUEST['letter'] ) ) {
    echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    }

    if ( isset( $_REQUEST['members_search'] ) ) {
    echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
    }

    if ( isset( $_REQUEST['type'] ) ) {
    echo '<input type="hidden" id="type" value="' . attribute_escape( $_REQUEST['type'] ) . '" name="type" />';
    }
    }

    Then at the beginning of members-loop.php, replace…

    <?php if ( bp_has_site_members( 'type=active&per_page=10' ) ) : ?>

    …with something like…

    <?php if ( bp_has_site_members( 'type=' . $_REQUEST['type'] . '&per_page=10' ) ) : ?>

    …but keep in mind that it’s bad practice to refer to any variable directly in the template; you should probably build a function to wrap around it and sanitize it (although in this case nothing bad could really come out of it.)

    See if something like this works?


    buddypresser
    Participant

    @buddypresser

    Thanks JJJ, I’ll try it and get back!


    buddypresser
    Participant

    @buddypresser

    OK That did the job!

    I had to do a bit more tweaking in the AJAX to make sure it was posting the ‘type’. From there I was able to put that into the hidden input and it was all fine and dandy.

    Thanks :D

    Out of interest, what did you mean by:

    …but keep in mind that it’s bad practice to refer to any variable directly in the template;

    ?

    Cheers.


    h4x3d
    Participant

    @h4x3d

    this works perfectly, thank you!


    h4x3d
    Participant

    @h4x3d

    grr,

    seems like I don’t get it to work as I wanted it:

    I am trying to display members on the /members/ directory by means of the ?s=

    search and trying to select more than one term.

    For instance:

    /members/?s=Team

    would return all people that have a custom profile field of “Team” – this works. great!

    but I would like to have

    /members/?s=Team&Red

    to show all people that have the custom profile field “Team” and “Red”.

    any pointers?

    This is doing my head in for days :((


    buddypresser
    Participant

    @buddypresser

    I read one of the moderators here recently say that, at present, this would require re-writing part of the search functionality (if not the whole thing)

    Not sure though, as I haven’t looked into it myself.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Member Directory sub-directories using $bp->current_action?’ is closed to new replies.
Skip to toolbar