Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] List Members based on extended profile field value

  • Avatar of Alan Niemies
    Alan Niemies
    Participant

    @alanniemies

    I’m trying to retrieve a specific Members Loop page at BuddyPress with members who chose Yes on a specific Radio Button (which has Yes/No options).

    For this, I created an specific Template page at my theme. Found some old topics here on forums and managed to get this code. Unfortunately, my code (below) isn’t working and I came to a dead end. Can anyone help me?

    <?php 
    $attend_value = "Yes";
    $db_query = "SELECT user_id FROM wp_bp_xprofile_data WHERE field_id = 13 AND value = \"" .$attend_value ."\""; 
    $match_ids = $wpdb->get_col($db_query);
    $get_these_members = 'include=' .$match_ids;
    ?>
    
    <?php if ( bp_has_members( $get_these_members ) ) : ?>

    I receive a “Sorry, no members were found.” even if the field id’s and values from the database are correct. What should be happening?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    Make sure this exists on the page before the query:
    global $wpdb;

    then try: “SELECT user_id FROM wp_bp_xprofile_data WHERE field_id = 13 AND value = ‘Yes'”;

    or “SELECT user_id FROM wp_bp_xprofile_data WHERE field_id = 13 AND value = $attend_value”;

    I don’t recall if you have to implode the $get_these_members array before passing it to bp_has_members, so check that too if the above queries don’t work.

    Avatar of Alan Niemies
    Alan Niemies
    Participant

    @alanniemies

    Hello shane! Thanks for the reply.

    I tried to turn them into an array and implode, but still nothing happened. My updated code:

    <?php 
    global $wpdb;
    $db_query = "SELECT user_id FROM wp_bp_xprofile_data WHERE field_id = 13 AND value = Yes";
    $match_ids = $wpdb->get_col($db_query);
    $get_these_members = array('include=' .$match_ids);
    $members_imploded = implode(",", $get_these_members);
    ?>
    
    <?php if ( bp_has_members( $members_imploded ) ) : ?>
    
    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    It’s already an array. No need to turn it into an array. And that not how to create an array anyways.

    Try:

    <?php
    global $wpdb;
    $db_query = "SELECT user_id FROM wp_bp_xprofile_data WHERE field_id = 13 AND value = 'Yes'";
    $match_ids = $wpdb->get_col($db_query);
    ?>
    <?php if ( bp_has_members( $match_ids ) ) : ?>

    If that doesn’t work, try:

    $members_imploded = 'include=' . implode(",", $match_ids);
    <?php if ( bp_has_members( $members_imploded ) ) : ?>
    Avatar of Alan Niemies
    Alan Niemies
    Participant

    @alanniemies

    Geez, not yet. I tried almost everything, triple-checked database and nothing :(

    Avatar of Alan Niemies
    Alan Niemies
    Participant

    @alanniemies

    Found the problem, it’s really simple: if we declare an empty “include” in bp_has_members, it displays a Members Loop with all members. Now it’s everything fine. Thanks a lot, @shanebp!

    Avatar of johnnymestizo
    johnnymestizo
    Participant

    @johnnymestizo

    http:// your site .com/members/?s= field value

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

You must be logged in to reply to this topic.