Relationship between custom fields
-
Hello.
Here I am Again with hopefully the last question and then don’t disturb You agin for long time ??
Is there a way to connect 2 or more fields between them?
This is my Scenario, that i think is kind of typical:
People in the registration have one Radio (I am male/female) Then inside their Profile there should be a field dropdown (I am searching for a male/female). Now Let’s suppose that a second user let’s say a male, want to search all the female searching a male. Or also only a female. How can be done? Thanks once againe
-
You can try the following code snippet to make the member directory search for a user based on the selected gender
I am searching for a male/female
.add_filter('um_prepare_user_query_args', 'um_112521_search_for_male_or_female', 10, 2 ); function um_112521_search_for_male_or_female( $query_args, $args ){ $user_id = get_current_user_id(); um_fetch_user( $user_id ); $search_gender = um_user("search_for_male_or_female"); $query_args['meta_query'][ ] = array( 'relation' => 'OR', array( 'key' => 'gender', 'value' => '=', 'compare' => $search_gender ), ); return $query_args; }
With the code above, you need to change the
search_for_male_or_female
with your meta name/key ofI am searching for a male/female
field. Ensure that theI am searching for a male/female
has the exactMale
andFemale
options same as the Gender field options.Regards,
Hello.
Thank You for the answer.
So, if I put the code as You told me:
add_filter('um_prepare_user_query_args', 'um_112521_search_for_male_or_female', 10, 2 ); function um_112521_search_for_male_or_female( $query_args, $args ){ $user_id = get_current_user_id(); um_fetch_user( $user_id ); $search_gender = um_user("gender_search"); $query_args['meta_query'][ ] = array( 'relation' => 'OR', array( 'key' => 'gender', 'value' => '=', 'compare' => $search_gender ), ); return $query_args; }
I got not results at all. eve without filtering, is simply empty the page of the directory
Strangerly, ifi take your code without modificatrions, i can filter but whathever i do, i got as the result the same sex persons. Is like i see all the person searching for example i am on the oflline site for the tests where i registered me and my wife. I put to me “I search for female” and for her i search for male. If i search for a female, it’s exiting my profile, the same happeningwith my wife. If i put for her “i search for a male”, only her profile will appear. this happening only without changing nothing to yyour code.
if i change this line
$search_gender = um_user("search_for_male_or_female");
with:
$search_gender = um_user("gender_search");
Nothing at all appear.
I double checked th metakey name and the option. Everything is ok.
The only difference is that the gender field is a radio, while thegender_search is a dropdown.
Could be that?
-
This reply was modified 3 years, 3 months ago by
roberton1973.
-
This reply was modified 3 years, 3 months ago by
roberton1973.
-
This reply was modified 3 years, 3 months ago by
roberton1973.
Switch two values in the array and the code snippet will give you the Member Directory listings depending on the profile’s gender search settings.
array( 'key' => 'gender', 'value' => $search_gender, 'compare' => '=' ),
Thanks also to You for your kind answe. Sadly the results don’t change. I always got the message that there are not members, even without filtering.
I think I am wrong something here:
$search_gender = um_user("gender_search"); $query_args['meta_query'][ ] = array( 'relation' => 'OR',
I tried also to put gender search in a single braket, but no results.
$search_gender = um_user('gender_search');
Thanks again
Thanks again. Sadly still not work.
I will put here again all the code with the LIKE correction:
add_filter('um_prepare_user_query_args', 'um_112521_search_for_male_or_female', 10, 2 ); function um_112521_search_for_male_or_female( $query_args, $args ){ $user_id = get_current_user_id(); um_fetch_user( $user_id ); $search_gender = um_user("gender_search"); $query_args['meta_query'][ ] = array( 'relation' => 'OR', array( 'key' => 'gender', 'value' => $search_gender, 'compare' => 'LIKE' ), ); return $query_args; }
Thanks so much for the time you tooked to try to solve my problem
Can you copy the values users has to choose from for these fields and show us here in the forum:
gender
gender_search
They are both set on
?ensko (Female)
Mu?ko (Male)Both in this exact order.
Gender is set as radio, while gender_search as Dropdown. Maybe there is the problem?
Sorry! I saw now that is Working, but in a different way that i was expecting. I wase put it in the profile I am searching for and then now, with the last correction i noticed later that i can see only the woman! that is a cool feature too, that i will take. Thanks. But it’s possible to set it as filter? that was my original question, and maybe if it would possible to add “Searching for both” like 3rd option to both profile and filter would be top!
Thanks & Regards.
Hi.
Any news on about ho to filter from gender directly in member directory?
Thanks
Unfortunately, you can only add the Gender filter to have Male and Female values. To add an extra option in the Gender filter, you can try the following code snippet:
add_filter("um_member_directory_filter_select_options","um_120121_show_extra_gender", 10, 3); function um_120121_show_extra_gender( $options, $values_array, $attrs ) { if( "gender" == $attrs["metakey"] ){ $options["both"] = "Both Female & Male"; } return $options; }
And the following code snippet is needed to query the Gender for both Male and Female:
add_filter('um_prepare_user_query_args', 'um_120121_search_for_male_and_female', 10, 2 ); function um_120121_search_for_male_and_female( $custom_query_args, $args ){ foreach( $custom_query_args['meta_query'] as $i => $m ){ if( isset( $m[0]["key"] ) ){ if( "gender" === $m[0]["key"] && "Both Female & Male" == $m[0]["value"] ){ $custom_query_args['meta_query']["has_both_gender"] = true; unset( $custom_query_args['meta_query'][ $i ]); } } } if( isset( $custom_query_args['meta_query']["has_both_gender"] ) ){ $custom_query_args['meta_query'][ ] = array( 'relation' => 'OR', array( 'key' => 'gender', 'value' => "Male", 'compare' => 'LIKE', ), array( 'key' => 'gender', 'value' => "Female", 'compare' => 'LIKE', ), ); unset( $custom_query_args['meta_query']["has_both_gender"] ); } return $custom_query_args; }
Regards,
Hi. thank You.
It does not seems to work for me.
When I go to member direcetroy, If choose that i search for a female, it displays only the persons searching for female profiles, instead to show all the women’s profile.
Insteat, if i Left only the code of Miss veronica, is filtering only because set in the user profile. For example, if in my profile i choose to see only women in member directory, it will. I would like to do the same, but directly from member directory, so user don’t need to have this field in the profile.
Thanks again
If you don’t need the
gender_search
field in the Profile Form, what’s the reference for the member directory to search gender based on the currently logged-in user’s interest? By default, the Gender filter in the Member Directory filters the Profiles by gender. If you search for females, it will show all females. Could you please clarify?Regards,
Hi.
I would like that the search for female or male is done from member directory and not set in the profile or alternatively, that would be possible to overwrite what choosen in the profile using the filter in member directory.
For example in the profile nothing is choosen and in that way will show both, then user go in member directory and choose whatever he/she wants.
Thanks and regards
-
This reply was modified 3 years, 3 months ago by
roberton1973.
Sorry, I’m a bit confused with the logic that you want to implement to the Member Directory.
Do you want to filter the Member Directory by the “gender_search” selected from the Profile Form? And then when the “gender_search” is empty or no selection, you want to display the Gender filter to display “Male” and “Female”?
Regards,
-
This reply was modified 3 years, 3 months ago by
- The topic ‘Relationship between custom fields’ is closed to new replies.