Skip to:
Content
Pages
Categories
Search
Top
Bottom

Filter User Query By BuddyPress Custom Profile Field


  • Jake Ward
    Participant

    @jakeward

    We have a custom BuddyPress profile field which is a select dropdown.

    Elsewhere in the site we have a user query, that pulls in users of a certain role. However, we need to filter these users again by those who have a certain value in the dropdown field. Is there a way to add this to to the WP_User_Query?

    I’ve seen documentation for BP_User_query but haven’t been able to get it to work.

                $args = array(
                'role' => 'vendor',
                'orderby' => 'display_name',
                'order'     => 'ASC',
                'number' => 5,                
                );
                $user_query = new WP_User_Query( $args );
    
Viewing 5 replies - 1 through 5 (of 5 total)

  • shanebp
    Moderator

    @shanebp

    WP_User_Query has an include parameter:
    include (array) – List of users to be included.

    WP_User_Query

    Gather the ids of the members you want and then use that array for include.


    Jake Ward
    Participant

    @jakeward

    Thanks Shane, but this needs to be a dynamic query as it will be constantly changing.


    shanebp
    Moderator

    @shanebp

    So write a dynamic query to get the ids that you want in include.
    I suggest using $wpdb->get_col.

    wpdb


    Jake Ward
    Participant

    @jakeward

    Thanks Shane, will take a look now.


    Jake Ward
    Participant

    @jakeward

    Thank you, Shane! This solved my problem. Much appreciated.

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