My Question is almost similar to author-specific-urls-in-wordpress and mapping-multiple-urls-to-same-page-in-wordpress. And i have followed the following steps
- Created a custom page (writer.php)
- Associated that page from dashboard
since all the writer are not being registered with word-press so WP build in author functionality is not of any help for me. So i created a custom URL something like
$author_page_url = home_url( '/' );
$author_page_url .='writer/'.$author_id[0];
where author_id is being fetched from the database.i have following entry in my function.php
add_action('init', 'add_my_rule');
function add_my_rule() {
global $wp;
$wp->add_query_var('args');
add_rewrite_rule('writer\/(.*)','index.php?pagename=writer&
args=$matches[1]','top');
}
and on writer.php i am doing something like
$params = get_query_var('args');
$ppp = get_option('posts_per_page');
if (!is_paged()) {
$custom_offset = 0;
} else {
$custom_offset = $ppp*($paged-1);
}
$args = array( 'meta_key' => 'writer', 'meta_value' => $params
,'numberposts' => $ppp,'offset' => $custom_offset);
$authorposts=get_posts($args);
My problem is when i am hitting the following URL http://localhost/blog/wordpress/writer/umesh-awasthi WP is giving me 404 Error.while the URL http://localhost/blog/wordpress/writer/ is working perfectly fine.
Initialy when i developed this, it was working fine and now i have no clue what is going wrong. Can any one help me to debug the problem.Thanks in advance.
Update
My initial doubt is that the rewrite rule is not working but not sure why