Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress Members Loop ordered by custom field value?

  • Avatar of Unit9
    Unit9
    Participant

    @unit9

    Hi guys, :D

    I’ve got a custom profile field that’s a five digit numerical value up to a maximum of 99999.

    I want to use the members loop to list members from the member with the highest value in that custom field to the member with the lowest value.

    Example:
    Bob – 99999
    John – 99998
    James – 99997

    etc. Is it possible to do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Avatar of shanebpdev
    shanebp
    Participant

    @shanebp

    It would be best to filter this at the query level.

    See do_action_ref_array( ‘bp_pre_user_query’, array( &$this ) );
    In function prepare_user_ids_query()
    In buddypress\bp-core\bp-core-classes.php

    Avatar of Unit9
    Unit9
    Participant

    @unit9

    Thanks Shane! Would this modify the page for every listing? I only want to do this for one custom page. :)

    Thanks!

    Avatar of shanebpdev
    shanebp
    Participant

    @shanebp

    You should be able to do a conditional based on the page slug, action or uri.
    But the user query might fire before that check can be run.
    Try a simple echo from a function on that hook, see where/when it appears.

    You could manipulate the members loop (stuff into array & resort)
    but that’s very inefficient unless you have less than 1000 users.
    And I’m not sure what effect it would have on pagination – I suspect not good.

    Avatar of Unit9
    Unit9
    Participant

    @unit9

    Thanks so much for your reponses Shane!

    So is there a way to do this within my theme without messing with the core members list code? :)

    Avatar of shanebpdev
    shanebp
    Participant

    @shanebp

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

You must be logged in to reply to this topic.