-
Author
-
December 7, 2014 at 01:58 #37938DavidParticipant
I need to display only the profiles of the opposite gender of the user who is logged in. (eg. Display only Females when a Male is logged in and vise versa)
I’ve used the code in this thread, and changed the field_id, etc. But for some reason i haven’t gotten it to work.
https://archived.seventhqueen.com/forums/topic/gender-related-question-sweetdate
Help would be greatly appreciated. Thank You.
December 7, 2014 at 05:23 #37946LauraModeratorHello, you also need to change the names, Muslim for Male / Men or what you want, and Muslima for Woman /Women
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
December 10, 2014 at 07:21 #38410DavidParticipantHi,
Thank you for the reply.
I had replaced the field names as well, but for some reason it doesn’t work.
Here’s the code I have
COPY CODEclass BP_Custom_User_Ids { private $custom_ids = array(); public function __construct() { $this->custom_ids = $this->get_custom_ids(); add_action( 'bp_pre_user_query_construct', array( $this, 'custom_members_query' ), 1, 1 ); add_filter( 'bp_get_total_member_count', array( $this, 'custom_members_count' ), 1, 1 ); } private function get_custom_ids() { global $wpdb; //figure out if the logged-in user is male or female $sex = xprofile_get_field_data( 403, bp_loggedin_user_id() ); if ( $sex == 'Man' ) $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 403 AND value = 'Woman'"; else $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 403 AND value = 'Man'"; $custom_ids = $wpdb->get_col( $query ); return $custom_ids; } function custom_members_query( $query_array ) { $query_array->query_vars['include'] = $this->custom_ids; } function custom_members_count ( $count ) { $new_count = count( $this->custom_ids ); return $new_count; } } function custom_user_ids( ) { new BP_Custom_User_Ids (); } add_action( 'bp_before_directory_members', 'custom_user_ids' );
December 10, 2014 at 07:23 #38411DavidParticipant( note [code] and [/code] aren’t in my php file, I put them in the message but apparently those aren’t the correct markup tags for this forum. )
December 10, 2014 at 09:03 #38416LauraModeratorHello, try this and let me know if its working, remember Man and Woman should be the exact option as you have in I am field.
COPY CODEclass BP_Custom_User_Ids { private $custom_ids = array(); public function __construct() { $this->custom_ids = $this->get_custom_ids(); add_action( 'bp_pre_user_query_construct', array( $this, 'custom_members_query' ), 1, 1 ); add_filter( 'bp_get_total_member_count', array( $this, 'custom_members_count' ), 1, 1 ); } private function get_custom_ids() { global $wpdb; //figure out if the logged-in user is male or female $sex = xprofile_get_field_data( 403, bp_loggedin_user_id() ); if ( $sex == 'Man' ) $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 403 AND value = 'Man'"; else $query = "SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 403 AND value = 'Woman'"; $custom_ids = $wpdb->get_col( $query ); return $custom_ids; } function custom_members_query( $query_array ) { $query_array->query_vars['include'] = $this->custom_ids; } function custom_members_count ( $count ) { $new_count = count( $this->custom_ids ); return $new_count; } } function custom_user_ids( ) { new BP_Custom_User_Ids (); } add_action( 'bp_before_directory_members', 'custom_user_ids' );
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
December 10, 2014 at 10:09 #38420DavidParticipantThank you for the quick reply!, I have it working now 🙂
It turns out I had edited the bp-custom.php in the framework/inc/ directory and not the bp-custom.php in /plugins directory. (I went back and checked the original post after I tried the code you posted without success, where you said in the plugins directory…)
The code I posted works correctly.
Thanks again!
December 10, 2014 at 10:10 #38421LauraModeratorHello, i’m glad it works! 🙂
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
September 12, 2015 at 11:41 #77300paoloeuvrardParticipantHello Laura,
I have the same problem, the code doesn’t work. Ihave an Id of 3 as you can see in the attached file.
It blocks my logins, or once it’s on I can’t log in wp-admin. And my members page is blank.
Any idea?
Thank you very much if you can help.
Cheers,
PaoloI got
<?php
class BP_Custom_User_Ids {private $custom_ids = array();
public function __construct() {
$this->custom_ids = $this->get_custom_ids();
add_action( ‘bp_pre_user_query_construct’, array( $this, ‘custom_members_query’ ), 1, 1 );
add_filter( ‘bp_get_total_member_count’, array( $this, ‘custom_members_count’ ), 1, 1 );}
private function get_custom_ids() {
global $wpdb;//figure out if the logged-in user is male or female
$sex = xprofile_get_field_data( 3, bp_loggedin_user_id() );if ( $sex == ‘Man’ )
$query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = ‘Man'”;
else
$query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = ‘Woman'”;$custom_ids = $wpdb->get_col( $query );
return $custom_ids;
}function custom_members_query( $query_array ) {
$query_array->query_vars[‘include’] = $this->custom_ids;
}
function custom_members_count ( $count ) {
$new_count = count( $this->custom_ids );
return $new_count;}
}function custom_user_ids( ) {
new BP_Custom_User_Ids ();
}
add_action( ‘bp_before_directory_members’, ‘custom_user_ids’ );
?>Attachments:
You must be logged in to view attached files.September 12, 2015 at 13:15 #77302paoloeuvrardParticipantHi Laura,
kindly discard my last message. The issue was with the bp-custom.php file.I added your code second to another one with another <?php … ?> instance, which caused it to break.
Everything’s fine now, except that I had to invert the values you published as follow:if ( $sex == ‘Man’ )
$query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = ‘Woman'”;
else
$query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 3 AND value = ‘Man'”;Thanks, you made my day anyway.
Cheers,
PaoloSeptember 13, 2015 at 21:39 #77459LauraModeratorHello, i am glad it helped you 🙂
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
-
AuthorPosts
The forum ‘Sweetdate – WordPress’ is closed to new topics and replies.