Find user by nicename and open profile

Question

I want to add filter function and show user profile page by using search form. This is what I have now:

function test_where_filter($where){
    global $wpdb;
    if( is_search() ) {
        $search= get_query_var('s');
        $query=$wpdb->prepare("SELECT id FROM $wpdb->users WHERE ( meta_key='user_nicename' AND meta_value LIKE '%%%s%%' )", $search ,$search);
        $authorID= $wpdb->get_var( $query );

        if($authorID){
            ...
        }

    }
    return $where;
}

add_filter('posts_where','test_where_filter');

Is my code correct and how to open author page if it will be found? Not a search result page, but user page with this link: example.com/author/nicename? Thank’s for any help with this!

0
, Alexander Goroshev 3 years 2020-04-01T08:52:22-05:00 0 Answers 83 views 0

Leave an answer

Browse
Browse