Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to get monthly archives for static pages. I tried to use the next code:

add_filter('getarchives_where','my_archives_filter');
function my_archives_filter($where_clause) {
return "WHERE post_type = 'page' AND post_status = 'publish'";
}

and in the sidebar I write:

add_filter('getarchives_where','my_archives_filter');               
wp_get_archives('type=yearly');
remove_filter ('getarchives_where','my_archives_filter');

But it doesn't work.

Can you help me?

Thanks.

share|improve this question
add comment

1 Answer

wp_get_archives already have post_type = 'post' by default and to replace it try this:

add_filter('getarchives_where','my_archives_filter');
function my_archives_filter($where_clause) {
    str_replace( "post_type = 'post'" , "post_type = 'page'" , $where );
}

in sidebar:

add_filter('getarchives_where','my_archives_filter');               
wp_get_archives('type=yearly');
remove_filter ('getarchives_where','my_archives_filter');
share|improve this answer
    
Thanks for your answer. Now in sidebar I get yearly archive but it gives me a 404 error when I follow de link (thedomain.com/2012) –  Rec Apr 15 '12 at 15:45
    
That is beacuse the archive template is set to show posts and not pages –  Bainternet Apr 15 '12 at 16:06
    
And how can I change it? –  Rec Apr 15 '12 at 16:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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