Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)
  • @zeeshanmba2014

    Participant

    To filter members who have filled out the xprofile field ‘dogs’ and selected either ‘poodles’ or ‘terriers,’ you can use the bp_has_members loop with a custom function to achieve this. Here’s how you can modify the code:

    php
    Copy code
    <?php
    // Create a custom function to filter members by xprofile field values
    function my_custom_ids($field_name, $values) {
    global $wpdb;

    // Prepare an array of values to match
    if (!is_array($values)) {
    $values = array($values);
    }

    // Generate the SQL query to retrieve user IDs with the specified field and values
    $sql = $wpdb->prepare(”
    SELECT user_id
    FROM {$wpdb->prefix}bp_xprofile_data
    WHERE field_name = %s
    AND value IN (‘” . implode(“‘,'”, $values) . “‘)
    “, $field_name);

    // Fetch the matching user IDs
    $user_ids = $wpdb->get_col($sql);

    // Return the user IDs
    return $user_ids;
    }

    // Define an array of values for ‘dogs’ xprofile field
    $dogs_values = array(‘poodles’, ‘terriers’);

    // Check if there are members matching the criteria
    if (bp_has_members(array(‘include’ => my_custom_ids(‘dogs’, $dogs_values)))) :
    ?>

    <!– Your member loop code here –>

    <?php
    endif; // End bp_has_members loop
    ?>
    In this modified code:

    We create a custom function my_custom_ids to query the database for user IDs based on the specified xprofile field name and an array of values.

    We define an array $dogs_values containing the values ‘poodles’ and ‘terriers’ that you want to search for.

    In the bp_has_members loop, we use the ‘include’ parameter to pass the array of user IDs returned by the my_custom_ids function. This ensures that the loop only includes members who have selected either ‘poodles’ or ‘terriers’ for the ‘dogs’ xprofile field.

    Make sure to replace <!– Your member loop code here –> with the code to display the members that match your criteria. This code should give you members who have filled out the xprofile field ‘dogs’ and selected either ‘poodles’ or ‘terriers.’

Viewing 1 replies (of 1 total)
Skip to toolbar