$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>url rewriting - Change author base and slug in author link|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

url rewriting - Change author base and slug in author link

matteradmin9PV0评论

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' ) ) { 
  var_dump($author_id);
 } 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

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' ) ) { 
  var_dump($author_id);
 } 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

Share Improve this question edited Feb 20, 2019 at 9:04 Mohamed Mokhtar asked Feb 20, 2019 at 8:43 Mohamed MokhtarMohamed Mokhtar 591 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

Post a comment

comment list (0)

  1. No comments so far