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.

Can anybody show me how to set a limit on wp_get_archives to show archives by month BUT only those for the year 2010 and above - so the 2009 monthly archives are not shown on the sidebar archive widget.

Thank you!

share|improve this question
add comment

1 Answer

If using "regular" query in theme file (sidebar.php for example), this code will help do the trick:

<?php wp_get_archives('type=monthly&limit=12'); ?>

The above (and below) will only show the last 12 months.

However if using a widget, then add this code to your functions.php file:

function my_limit_archives( $args ) {
    $args['limit'] = 12;
    return $args;
}
add_filter( 'widget_archives_args', 'my_limit_archives' );
add_filter( 'widget_archives_dropdown_args', 'my_limit_archives' );

Note: In both of the above code examples, I don't remember where I got the original code from (Google can probably find it?). I just pulled this from a fix I effected on another theme.

Finally, this resource may help point you in the direction to list archives only from 2010 to the present: http://www.wpbeginner.com/wp-themes/how-to-customize-the-display-of-wordpress-archives-in-your-sidebar/

I hope the above helps you in some way! :)

share|improve this answer
    
Further: I found this resource which may help: [en.forums.wordpress.com/topic/archives-by-year-1] See the comment that discusses [archives type=yearly=2009] I found the source for the above here: [wordpress.stackexchange.com/questions/19945/… –  Roger Nov 3 '11 at 3:11
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.