• Resolved Marc_O

    (@marc_o)


    Hello,
    I have an issue with the search in the member directory of my website. I want people to be able to search the members using the place where they work. The problem is that some can have two places.
    At first I was using the search fiels where you just type the name of the place but it’s not working well because if you search for “some place” nothing appear if the name of the place if “some-place”.

    So I’ve put a dropdown for people to directly choose the right place but it’s only working for one field at the time abd it doens’t make sense to put the two dropdowns and ask people to search in each one.

    Is there a way with an hook to ask the query done with one dropdown to search inside the other place field too ?

    If not, is there a way to change the way the search field and make it more flexible ? I mean for example if I search for “some place” I have the result for “some-place” that is taken into account ?

    Thank you

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @marc_o

    You can use this filter hook to modify the member directory query:
    um_prepare_user_query_args
    params:
    $query_args
    $directory_data_settings

    Regards,

    Thread Starter Marc_O

    (@marc_o)

    Hello,
    Thank you for your answer.
    Do you have an example of a code for modifying a query so I can see how it works?
    Regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @marc_o

    Here’s an example query that searches for a meta key and value:

    add_filter("um_prepare_user_query_args","um_12102020_prepare_user_query_args", 10, 2);
    function um_12102020_prepare_user_query_args( $args, $directory_settings ){
       
        $args['meta_query'][ ] = array(
            'key'     => '_my_custom_key',
            'value'   => 'Value I am looking for',
            'compare' => '='
        );
    
       return $args;
    }

    Regards,

    Thread Starter Marc_O

    (@marc_o)

    Hello,

    Thank you for this example of code but i’m not sure I understand of I can use it for my case.
    In the first message you said that I should use the params $query_args and $directory_data_settings but it’s not in your example code.
    Form the meta query I guess that the key is the field in wich I search the value, is it there I put the two fields “place1” and “place2” with a “or” logic ?
    Last thing is the ‘Value I am Looking for’ that I don’t understand. Is it the search of the user ? If so it’s dynamic, how can I get it into the code ?
    Thank you
    Regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @marc_o

    They are the same params I just made it different and shorthand.

    Here’s another example to add multiple meta query:

    add_filter("um_prepare_user_query_args","um_12102020_prepare_user_query_args", 10, 2);
    function um_12102020_prepare_user_query_args( $args, $directory_settings ){
       
        $args['meta_query'][ ] = array(
            'key'     => 'place1',
            'value'   => 'Value I am looking for 1',
            'compare' => '='
        );
    
        $args['meta_query'][ ] = array(
            'key'     => 'place2',
            'value'   => 'Value I am looking for 2',
            'compare' => '='
        );
    
       return $args;
    }
    

    Feel free to re-open this thread by changing the topic status to “Not Resolved” so we can get back to you.

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search into two fields at once in the members directory’ is closed to new replies.