// this function should return array with users ids, like this: array(123,3423,21,34231)
$user_ids = my_custom_ids( 'gender', 'female' );
if ( bp_has_members( array(
'type' => 'online',
'include' => $user_ids
) ) ) :
Hi @slaffik,
Thank you for helping me. Unfortunately, tried th function and it did not work. Do you have any ideas?
Regards,
Mark
Anybody else have any ideas as to why this function isn’t working?
Thanks!
Please post all your code in pastebin, including my_custom_ids()
. And are you sure, that you have any females online?
Hi @slaffik,
The code I am using on in my template is below. I am positive females are online as this is running on my local box and I have multiple female and male testing accounts that I am using for testing.
<?php
$user_ids = my_custom_ids( 'gender', 'female' );
if ( bp_has_members( array( 'type' => 'online', 'include' => $user_ids ) ) ) : ?>
Also, I am using the following (taken from the codex) in my functions.php to get these custom ids to work, just in case you need this. And I have verified custom ids are in fact working.
function my_custom_ids( $field_name, $field_value = '' ) {
if ( empty( $field_name ) )
return '';
global $wpdb;
$field_id = xprofile_get_field_id_from_name( $field_name );
if ( !empty( $field_id ) )
$query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id;
else
return '';
if ( $field_value != '' )
$query .= " AND value = '" . $field_value . "'";
/*
LIKE is slow. If you're sure the value has not been serialized, you can do this:
$query .= " AND value = '" . $field_value . "'";
*/
$custom_ids = $wpdb->get_col( $query );
if ( !empty( $custom_ids ) ) {
// convert the array to a csv string
$custom_ids_str = 'include=' . implode(",", $custom_ids);
return $custom_ids_str;
}
else
return '';
}
Really appreciate your help!
Best Regards,
Mark
Please read carefully what I have written in my code section.
// this function should return array with users ids, like this: array(123,3423,21,34231
Your my_custom_ids()
returns a comma separated string with redundant text, while it should return an array or just comma separated list. Instead of $custom_ids_str = 'include=' . implode(",", $custom_ids);
you should have $custom_ids_str = implode(",", $custom_ids);
or better just return return $custom_ids;
Hi @slaffik,
Replacing $custom_ids_str = 'include=' . implode(",", $custom_ids);
with $custom_ids_str = implode(",", $custom_ids);
or return $custom_ids;
seems to have resolved my issue! I have to run out the door so I plan on doing more testing when I get home, but so far I believe it is working. After I get home and do some thorough testing I will let you know for sure if the issue is resolved. You rock man, really appreciate your help. Talk soon.
Regards,
Mark
Hi @slaffik,
Just got home and did some additional testing. It is working! This ticket can be resolved. Thank you so much for all your help, really appreciate it.
Best Regards,
Mark