Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Rachel Cherry

    (@bamadesigner)

    Ok. Here’s what I setup. I added a filter that you can hook into, run your search, and then return your user search results in the form of an array of user IDs.

    I’d love your help testing out my code. You can access it on my GitHub or in the plugin’s WordPress SVN repo trunk.

    Example filter:

    add_filter( 'authors_autocomplete_mb_custom_user_search_user_ids', 'authors_autocomplete_custom_user_search', 1, 4 );
    function authors_autocomplete_custom_user_search( $user_ids, $search_term, $post_id, $post_type ) {
    
       // run your search code
       // ...
       // ...
       // let's say your search returned 2 users
       // with the user IDs 4 and 10
       // send those IDs back through the filter
       $search_results = array( 4, 10 );
    
       if ( $search_results )
          return $search_results;
    
       // filters must always return a value
       else
          return $user_ids;
    
    }

    Thread Starter aaronrobb

    (@aaronrobb)

    Ok, i’m starting to see this, but because i’m still a novice programmer, where would I call the custom field.

    For example, normally i use this:

    $value = cimy_uef_sanitize_content(get_cimyFieldValue($user->ID, 'ADDRESS'));

    to call the field. How would i show results including these fields?
    Based on the original plugin, I could get away with removing the login from the seach and replace with this custom field. For our site login and email are the same, so its just doubling it up.

    I’m going to start experimenting with your filter and will respond if I figure it out myself.

    Plugin Author Rachel Cherry

    (@bamadesigner)

    Ok. I made a tiny tweak to the main plugin file so get that update and then try this filter out. It searches all of the CIMY user fields.

    add_filter( 'authors_autocomplete_mb_custom_user_search_user_ids', 'authors_autocomplete_custom_user_search', 1, 4 );
    function authors_autocomplete_custom_user_search( $user_ids, $search_term, $post_id, $post_type ) {
       global $wpdb;
       return $wpdb->get_col( "SELECT users.ID, cimy_uef_data.VALUE FROM $wpdb->users users LEFT JOIN {$wpdb->prefix}cimy_uef_data cimy_uef_data ON cimy_uef_data.USER_ID = users.ID WHERE ( cimy_uef_data.VALUE LIKE '%$search_term%' OR users.user_login LIKE '%$search_term%' OR users.display_name LIKE '%$search_term%' OR users.user_email LIKE '%$search_term%' ) ORDER BY users.ID ASC" );
    }
    Plugin Author Rachel Cherry

    (@bamadesigner)

    If you’d like to search a specific field, use the following query instead. Notice my placement of ‘ORGANIZATIONNAME’. Just replace that with your specific CIMY field name.

    add_filter( 'authors_autocomplete_mb_custom_user_search_user_ids', 'authors_autocomplete_custom_user_search', 1, 4 );
    function authors_autocomplete_custom_user_search( $user_ids, $search_term, $post_id, $post_type ) {
       global $wpdb;
       return $wpdb->get_col( "SELECT users.ID, cimy_uef_data.VALUE FROM $wpdb->users users LEFT JOIN {$wpdb->prefix}cimy_uef_data cimy_uef_data ON cimy_uef_data.USER_ID = users.ID LEFT JOIN {$wpdb->prefix}cimy_uef_fields cimy_uef_fields ON cimy_uef_fields.ID = cimy_uef_data.ID AND cimy_uef_fields.NAME = 'ORGANIZATIONNAME' WHERE ( cimy_uef_data.VALUE LIKE '%$search_term%' OR users.user_login LIKE '%$search_term%' OR users.display_name LIKE '%$search_term%' OR users.user_email LIKE '%$search_term%' ) ORDER BY users.ID ASC" );
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add another value to search?’ is closed to new replies.