Monday, February 6, 2023
HomeWordPress Developmentplugin growth - Why is WordPress wrapping seek for customers that appears...

plugin growth – Why is WordPress wrapping seek for customers that appears like integers with asterisks and the way do I repair it?


I’ve obtained a customized meta discipline for customers known as “user_ein”. It seems to be like an integer however is a string of quantity and it might probably begin with the quantity “0”. I’ve the next code in a customized plugin so customers will be searched on this quantity:

operate search_by_user_ein( $question ) {
    if ( ! is_admin() || ! $query->query_vars['search'] ) {
        return $question;
    }
    world $wpdb;
    $search = trim( $query->query_vars['search'] );
    // Uncomment subsequent line to get search engaged on user_ein discipline
    // $search = trim( $search, '*' );
    $search="%" . $wpdb->esc_like( $search ) . '%';

    $query->query_from .= " LEFT JOIN {$wpdb->usermeta} ON {$wpdb->customers}.ID = {$wpdb->usermeta}.user_id";

    $query->query_where .= $wpdb->put together( " OR ({$wpdb->usermeta}.meta_key = 'user_ein' AND {$wpdb->usermeta}.meta_value LIKE %s)", $search );
    return $question;
}
add_filter( 'pre_user_query', 'search_by_user_ein' );

This did not work. If I put in “552398” into the search discipline, nothing was returned despite the fact that there’s a person with the user_ein. After some head scraching, I dumped out the question and observed that it was looking out on *552398*. The search time period was getting surrounded by asterisks.

To repair the issue, I added this code in after getting the search time period from the $question object:

$search = trim( $search, '*' );

Issues appear to work completely now however I am apprehensive there is likely to be some unintended penalties. Is there a greater repair than this?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments