Wordpress custom author urls -


i want implement custom author urls.

currently author urls this: http://site.com/author/author-name/

i want http://site.com/my-custom-url-here

for each individual user. have tried using author_rewrite_rules filter, using following code, converts url correctly gives me page not found message when browse url

add_filter('author_link', 'no_author_base', 1000, 3);   function no_author_base($link, $author_id) {       $link_base = trailingslashit(get_option('home'));       $link = preg_replace("|^{$link_base}author/|", '', $link);       return $link_base . $link;   }   add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules');   function no_author_base_rewrite_rules($author_rewrite) {         global $wpdb;       $author_rewrite = array();       $authors = $wpdb->get_results("select user_nicename nicename $wpdb->users");       foreach($authors $author) {           $author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]';           $author_rewrite["({$author->nicename})/?$"] = 'index.php?author_name=$matches[1]';       }          return $author_rewrite;   }   

any appreciated!

thanks. update

problem solved!, did not know calling flush_rewrite_rules function.

solved!

here's how did it:

i did not need author_link filter removed it, custom urls stored in usermeta table fetched them , passed them rewrite array, , importantly i did not know flushing rewrite cache , reason original code not working

heres full code:

add_filter('author_rewrite_rules', 'my_author_url_with_custom_url_rewrite_rules'); function my_author_url_with_custom_url_rewrite_rules($author_rewrite) {    global $wpdb;   $author_rewrite = array();   $authors = $wpdb->get_results("select id, user_nicename nicename, meta_value profile_name                                     $wpdb->users                                      left join wp_usermeta on wp_usermeta.user_id = $wpdb->users.id                                      meta_key = 'profile_name'");        foreach ($authors $author) {     $author_rewrite["{$author->profile_name}/page/?([0-9]+)/?$"] = 'index.php?author_name=' . $author->nicename . '&paged=$matches[1]';     $author_rewrite["{$author->profile_name}/?$"] = "index.php?author_name={$author->nicename}";   }   return $author_rewrite; } flush_rewrite_rules(false); 

dont forget comment flush_rewrite_rules call after done rewrite rules, expensive!


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -