Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Search/Filter based on custom field


  • mdrabble
    Participant

    @mdrabble

    What is the best method of creating some php/MySQL code to search a custom field and then display the UserID and Name (and possibly other details if needed) of the users from that search.

    Cheers 🙂

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

  • mdrabble
    Participant

    @mdrabble

    Sorted…… found mycustom_ids function and membersloop

    Just need to sort how to display the details.

    Happy Days


    mdrabble
    Participant

    @mdrabble

    Ok, all working but how can i Get members-loop to sort on the last name? or better still, show username by last name, first name

    Any hints, clues, pointers welcome 🙂


    dsided
    Participant

    @dsided

    Could you share your code to show First Name and Last name? I’m trying to get this to work with Memberpress. Thanks!


    mdrabble
    Participant

    @mdrabble

    I found and added this code to my functions.php within my theme folder – this allows you to sort the members by lastname.

    function alphabetize_by_last_name( $bp_user_query ) {
        if ( 'alphabetical' == $bp_user_query->query_vars['type'] )
            $bp_user_query->uid_clauses['orderby'] = "ORDER BY substring_index(u.display_name, ' ', -1)";
    }
    add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );

    I then created a custom page template within my theme and pasted the membersloop.php code into that page and made some formatting changes as I only wanted it to affect this one page.

    On the line:
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) : ?>

    I added ‘&populate_extras&type=alphabetical’

    so the line now shows as:
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&populate_extras&type=alphabetical' ) ) : ?>

    Hope that helps.


    dsided
    Participant

    @dsided

    Thanks @mrdrabble that worked a treat!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar