Problem in User Custom Field

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Problem in User Custom Field

This topic contains 6 replies, has 2 voices, and was last updated by brunopelei brunopelei 6 years ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17223
    brunopelei
    brunopelei
    Participant

    I’m using buddypress and I have multiple users text-only custom fields created with the default buddypress utility and not with ACF.

    I use KLEO Theme and I disabled all other search systems.

    I created two fields: Gender and City of type “Text Box”.

    One user has set sex = woman and city = Naples while another sex = man and city = Verona.

    I did tests for over 6 or 7 hours with 1000 different combinations with AND, OR and other settings.

    Eg
    If I type: “donna napoli” or “uomo verona”, it finds nothing.
    If I type: “woman man” find both users.

    I would like to find users based on their custom fields to find ONLY those that ONLY contain ALL the words entered.

    Example: I would like to search for all users that contain: MAN VERONA ENGINEER ACEA
    where users custom fields are: SEX – CITY – STUDY TITLE – COMPANY all type “Text Box”.

    I bought the plugin to do this.

    Where am I wrong?

    I await your response

    thank you

    #17228
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    The problem in this case is, that combining the logic inbetween the fields (title, custom fieldst etc..) is not possible, as it is not treated as one single ‘bunch’ of data by mysql. There is the index table engine resolving this issue, but at the moment it only words with custom post types and attachments.

    The AND logic in this case means, that all keywords should match, in at least one of the fields. Meaning that for example ‘donna napoli’ must both match either the title or the one of the custom fields (or any of the selected fields), which is not the case. This is due to the fact that it is not possible to check wether any of the keywords matches any of the fields in previous statements.

    The only possible solution (if this is even possible), is to tweak the search query itself directly in the file. From what you described, you want all of the words, matching at least once, in any of the fields + matching the bio/title? It might be doable, I am honestly not sure.

    If you can add temporary FTP and back-end access, I might be able to try to make a minor customization to the user search file, to see if this is possible in any ways.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #17229
    brunopelei
    brunopelei
    Participant

    Hello
    Yesterday I kept trying to figure out to the point of editing the “ajax-search-pro/includes/classes/search/class-asp-search-users.php” file.
    I found the relative piece of code and I understood why.
    So I have to decide whether to provide the user with a single multiline text field in which to perform the searches or customize the code of the file.
    I thank you for the answer you gave me.
    The plugin is still excellent and its layout very pleasant.

    Bruno

    #17230
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Bruno,

    I think a single text field would be much more simpler – but this gave me an even better idea.

    How about using a custom code in a hook, so when the user registers/edits it’s profile, it would create a ‘hidden’ meta field. Into that meta field the code would aggregate all the information you need for searching. On the plugin back-end, you would only need to select this field, and nothing else.

    I have made a sample skeleton code:

    add_action( 'profile_update', 'asp_additional_data_profile_update', 10, 1 );
    add_action( 'user_register', 'asp_additional_data_profile_update', 10, 1 );
    function asp_additional_data_profile_update( $user_id ) {
        $meta_value = "";
        $meta_key = '_usearch_data';
    
        // Gather all the search data into the $meta_value variable
    
        update_user_meta( $user_id, $meta_key, $meta_value);
    }

    This hook should trigger whenever a profile is added/edited. So in the commented section, you should aggregate all the string data you need into the $meta_value variable. Using the $user_id variable, you can get the user first:

    $user = get_userdata($user_id);

    Then, as you have the $user variable, that includes the name and all that. So if you need the first and last nem, you could do:

    $meta_value .= ' '.$user->first_name.' '.$user->last_name;

    Then get any meta you want:

    $val = get_user_meta($user_id, 'field_name', true);
    if ( $val !== false )
        $meta_value .= ' '.$val;

    ..and in the end you will get all the information in one field. Then all you need is to choose this field on the back-end of the search: https://i.imgur.com/EbscHA0.png
    All the other fields you can disable.

    I hope this helps 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #17231
    brunopelei
    brunopelei
    Participant

    ciao Ernest

    your idea is very very good !

    I try to do it!

    This php code I have to put it in some file of your plugin or I can put it in my mini plugin that accepts php and javascript code?

    Bruno

    #17240
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Bruno,

    Definitely use a custom plugin or a child theme with functions.php file.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #17241
    brunopelei
    brunopelei
    Participant

    since yesterday I’m trying in my plugin but the event is not captured and forcing the call to the function does not read all the fields and does not save the result.
    I will continue to try.
    thanks and good job
    Bruno

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Problem in User Custom Field’ is closed to new replies.