@puzzld1
Active 1 year, 2 months ago
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Thanks for your response! It is giving me the members who have filled out ‘dogs’ with ‘poodles’ or ‘terriers’, but it then continues on with a random list of members who have filled out ‘dogs’ with something else or not at all. Here is exactly what I have, members loop included:
<?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)))) : ?> // Members loop here <?php bp_nouveau_pagination( 'top' ); ?> <ul id="members-list" class="<?php bp_nouveau_loop_classes(); ?>"> <?php while ( bp_members() ) : bp_the_member(); ?> <li <?php bp_member_class( array( 'item-entry' ) ); ?> data-bp-item-id="<?php bp_member_user_id(); ?>" data-bp-item-component="members"> <div class="list-wrap"> <div class="item-avatar"> <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar( bp_nouveau_avatar_args() ); ?></a> </div> <div class="item"> <div class="item-block"> <h2 class="list-title member-name"> <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a> </h2> <?php bp_nouveau_members_loop_buttons(array('container' => 'ul','button_element' => 'button',)); ?> </div> <?php do_action( 'bp_after_members_loop' ); ?> </div><!-- // .item --> </div> </li> <?php endwhile; ?> </ul> <?php bp_nouveau_pagination( 'bottom' ); ?> <?php else : bp_nouveau_user_feedback( 'members-loop-none' ); endif; ?>
Also, in a separate members loop, how would I write something that would give me all members that filled out the xprofile field ‘dogs’ with any value AND filled out the xprofile field ‘shirt size’ with the value ‘small’?
Viewing 2 replies - 1 through 2 (of 2 total)