• Resolved roberton1973

    (@roberton1973)


    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

Viewing 15 replies - 16 through 30 (of 32 total)
  • Thread Starter roberton1973

    (@roberton1973)

    Hi @champsupertramp

    Yes sort of it. I want that in the filter, the members can always choose between Female and Male, If they put for example to search for female in the profile, in the beginning when they go on members there will be showed only female profile, but with the filter they should always be able to decide to change what they want to be showed and nothing selected, is meaning to show both the gender.

    Thread Starter roberton1973

    (@roberton1973)

    Hi @champsupertramp

    Yes sort of it. I want that in the filter, the members can always choose between Female and Male, If they put for example to search for female in the profile, in the beginning when they go on members there will be showed only female profile, but with the filter they should always be able to decide to change what they want to be showed and nothing selected, is meaning to show both the gender.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @roberton1973

    Sorry for the late response. Please try the following code snippets:

    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 );
        $has_gender_filter = false;
        foreach( $query_args['meta_query'] as $i => $m ){
            if( isset( $m[0]["key"] ) ){
                if( "gender" === $m[0]["key"] ){
                    $has_gender_filter = true;
                }
            }
        }
    
        if( $has_gender_filter == false ){
            $search_gender = um_user("search_for_male_or_female");
            $query_args['meta_query'][ ] = array(
                'relation' => 'OR',
                array(
                    'key'       => 'gender',
                    'value'     => $search_gender,
                    'compare'   => 'LIKE'
                ),
            );
        }
    
        return $query_args;
    }

    The above code will filter the Member Directory by search_for_male_or_female value on the first page load. And then if you filter with the Gender Dropdown, it will search the directory with the selected value in the dropdown.

    Regards

    Thread Starter roberton1973

    (@roberton1973)

    Hi.

    As usual, thank You for Your answer.

    Sadly does not work for me. For sure I wrong something:

    I have 2 distinct field: 1 for the gender that everyone insert when register,

    and another one called “Searching for” (meta ‘gs’) that i wan to use to search among the registeresd user. Maybe this clearify better.

    As You can see instead of the slider is appearing 2 textbox asking data from and data to

    Thanks

    • This reply was modified 4 years, 6 months ago by roberton1973.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @roberton1973

    Did you mean the Gender Interest field’s meta key is gs? If so, please try this modified code:

    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 );
        $has_gender_filter = false;
        foreach( $query_args['meta_query'] as $i => $m ){
            if( isset( $m[0]["key"] ) ){
                if( "gender" === $m[0]["key"] ){
                    $has_gender_filter = true;
                }
            }
        }
    
        if( $has_gender_filter == false ){
            $search_gender = um_user("gs");
            $query_args['meta_query'][ ] = array(
                'relation' => 'OR',
                array(
                    'key'       => 'gender',
                    'value'     => $search_gender,
                    'compare'   => 'LIKE'
                ),
            );
        }
    
        return $query_args;

    Regards,

    Thread Starter roberton1973

    (@roberton1973)

    Hi,

    I got an error “Unexpected end of file”, Without the code everything is ok.

    Thanks

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @roberton1973

    Sorry, there was a missing } in the previous code. Please try this one:

    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 );
        $has_gender_filter = false;
        foreach( $query_args['meta_query'] as $i => $m ){
            if( isset( $m[0]["key"] ) ){
                if( "gender" === $m[0]["key"] ){
                    $has_gender_filter = true;
                }
            }
        }
    
        if( $has_gender_filter == false ){
            $search_gender = um_user("gs");
            $query_args['meta_query'][ ] = array(
                'relation' => 'OR',
                array(
                    'key'       => 'gender',
                    'value'     => $search_gender,
                    'compare'   => 'LIKE'
                ),
            );
        }
    
        return $query_args;
    }

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @roberton1973

    This thread has been inactive for a while so weโ€™re going to go ahead and mark it Resolved…

    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and weโ€™d be happy to help… ๐Ÿ™‚

    Regards,

    Thread Starter roberton1973

    (@roberton1973)

    Hi.

    Sorry fo the very late answer, but i was really discouraged, from this, because nothing it seems to work. Now I got an idea to change a little the point of view… Is it possible to create 3 links like Female, Malem All? I will then insert in the page through Elementor…

    I think that the link should be something as mysite.xxx/?gender=female or male or default

    Thanks

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @roberton1973

    Try filtering the Member Directory form with the default gender filter. Once the filter is set, copy the URL parameter. It should look like this:
    http://yoursite.com/members/?filter_gender_98ab9=Male

    Now, to create links, you can try the following URL pattern:
    MALE:
    http://yoursite.com/members/?filter_gender_98ab9=Male
    FEMALE:
    http://yoursite.com/members/?filter_gender_98ab9=Female
    ALL:
    http://yoursite.com/members/

    This parameter will be different from your filter filter_gender_98ab9.

    Regards,

    Thread Starter roberton1973

    (@roberton1973)

    Hello,

    Hmy code is ?filter_gender_3d9fe=ลพensko for female for example, but i still see everyone. Can be maybe for the special serbian caracther?

    Thanks

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @roberton1973

    Are you sure that the gender name is in lowercase and not capitalized?

    Regards,

    Thread Starter roberton1973

    (@roberton1973)

    Hi.

    Yes it is. I copied-pasted from the options to be sure

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @roberton1973

    Did you remove the custom code? and see if this is a conflict issue with the code?

    Regards.

    Thread Starter roberton1973

    (@roberton1973)

    Hi. I removed the code, but without success.

    I took a screenshot of the field also here.

    Gender

    Thanks

Viewing 15 replies - 16 through 30 (of 32 total)

The topic ‘Relationship between custom fields’ is closed to new replies.