Possible to search by author name with default WordPress search function?

Maybe you can try adding your condition directly in the query string, using something like this

function wpse_29570_where_filter($where){
        global $wpdb;
        if( is_search() ) {
            $search= get_query_var('s');
            $query=$wpdb->prepare("SELECT user_id  FROM $wpdb->usermeta WHERE ( meta_key='first_name' AND meta_value LIKE '%%%s%%' ) or ( meta_key='last_name' AND meta_value LIKE '%%%s%%' )", $search ,$search);
            $authorID= $wpdb->get_var( $query );

            if($authorID){
                $where = "  AND  ( wp_posts.post_author = {$authorID} ) ";
            }

         }
         return $where;
    }

    add_filter('posts_where','wpse_29570_where_filter');

Leave a Comment

error code: 523