Hello im trying to change the author link from mysite/author/username to mysite/companies/dataFromUserMetabox

i tried the approach from this answer chage author url

its working the url changed but the problem is when i try to get the author id in author.php template

if ( $author_id = get_query_var( 'author' ) ) { 
 } else {
    echo 'no author id';

the link mysite/companies/dataFromUserMetabox return false

but the link mysite/companies/username return the author id

the default author slug even with the new author base "companies" is working but with the new slug its not, so im guessing there nothing wrong with changing the base from author to companies

1 Answer 1


i found out what i was doing wrong, i used this part like i mentioned

add_filter( 'request', 'wpse5742_request' );
function wpse5742_request( $query_vars )
if ( array_key_exists( 'author_name', $query_vars ) ) {
    global $wpdb;
    $author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='nickname' AND meta_value = %s", $query_vars['author_name'] ) );
    if ( $author_id ) {
        $query_vars['author'] = $author_id;
        unset( $query_vars['author_name'] );    
return $query_vars;

and changed the meta_key="nickname" in $author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='nickname' AND meta_value = %s", $query_vars['author_name'] ) ); with my custom metabox meta key this managed to find the author id and add it to the $query_vars successfully

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.