I've got a cpt called 'blog', now I would like to list all authors that contributed to that cpt. Also I would like to list all blogposts (from the 'blog' cpt) grouped in months, like wp_get_archives() does.
Authors. I tried to use wp_list_authors but it only lists authors from regular posts, not cpt's. I only want list authors of the 'blog' cpt. What to do?
Monthly archives. I tried to use wp_list_archives() following instructions from Bainternet (here: Get monthly archives for custom post type) and that lists "monthname year", looks great. BUT, the permalinks created looks like this: www.example.com/2011/10
...and that leads nowhere! I get a 404 error. All the 'blog' cpt posts are located under www.example.com/blog and I want the date archive url to include /blog as well.So maybe it's just a rewrite thing but I do fix that?Just manually typing www.example.com/blog/2011/10 only gets me to the 404 error page also.
Hope you can help me!
Update 1
I managed to rewrite the urls to the archives so now they look like this: www.example.com/blog/2011/10
This is the code I used for the rewrite:
add_rewrite_tag('%blog-date%','([\d]{4}-[\d]{2}-[\d]{2})');
add_action( 'init', 'blog_rewrites' );
function blog_rewrites() {
add_rewrite_rule( "blog/day/([\d]{4}-[\d]{2}-[\d]{2})/?$", 'index.php?post_type=blog&blog-date=$matches[1]', 'top' );
}
add_filter( 'query_vars', 'blog_vars' );
function blog_vars ( $vars ) {
$vars[] = 'blog-date';
return $vars;
}
But I still get the 404 error though...
Update 2
Applying code from @Bainternet's response below I was able to get my authors list functioning but I still get a 404 on my monthly archives links. The url seems correct though: www.example.com/blogg/2011/10 This is the code from my functions.php right now:
add_filter('get_archives_link', 'blog_archive_links');
function blog_archive_links($html){
$home_url = home_url();
$home_url_with_blog = $home_url .'/blogg';
return str_replace($home_url,$home_url_with_blog,$html);
}
//to match http://www.example.com/blog/2011/12/1/ use
add_rewrite_rule('^blogg/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$','index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]','top');
//to match http://www.example.com/blog/2011/12/1/page/2 use
add_rewrite_rule('^blogg/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&page=$matches[4]','top');
//to match http://www.example.com/blog/2011/12/ use
add_rewrite_rule('^blogg/([0-9]{4})/([0-9]{1,2})/(?$','index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]','top');
//to match http://www.example.com/blog/2011/12/page/2 use
add_rewrite_rule('^blogg/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$','index.php?post_type=blogg&year=$matches[1]&monthnum=$matches[2]&page=$matches[3]','top');
function Cpt_getarchives_where_filter( $where , $r ) {
$post_type = 'blogg';
return str_replace( "post_type = 'post'" , "post_type = '$post_type'" , $where );
}
And this is the code in my sidebar.php:
add_filter( 'getarchives_where' , 'Cpt_getarchives_where_filter' , 10 , 2 );
wp_get_archives();
remove_filter('getarchives_where' , 'Cpt_getarchives_where_filter' , 10 );
As you can see my cpt isn't called 'blog', it's actually called 'blogg', that's the Swedish spelling, shouldn't matter though. Also, I'm not using any plugin to get the cpt archives to work, I've simply created a file called archive-blogg.php and set the permalinks for the blogposts in the 'blogg' cpt to '/blogg' using a plugin called 'Custom Post Permalinks' that doesn't seem to be around anymore. It seems to do everything else right but I could try to replace that plugin with some code in functions.php.
Apart from that, anything else that could be tested to get this to work?