How to remove current year from wp_get_archives

Does anyone know how to exclude the current year from

$args = array(
    'limit'           => '',
    'format'          => 'html', 
    'before'          => '',
    'after'           => '',
    'show_post_count' => false,
    'echo'            => -1,
    'order'           => 'DESC',
    'type' => 'yearly',
    'paged'=>$paged,
    'post_type'     => 'my_post_type'
    );
    wp_get_archives( $args );

This basically outputs all the years on my custom archive page. I want to exclude the current year from it.

1 Answer
1

As you can see from the source code of wp_get_archives (line 1791 currently) the query is hardcoded. There is no filter to influence it. This means you have to correct the result afterwards. This is fairly easy if you set echo => 0 in the args, so the result is returned in stead of echoed. Then all you have to do is remove the first link that is returned:

$pattern = "/<a.*?<\/a>/";
$replacement = "";
$archives = wp_get_archives ($args);
preg_replace ($pattern, $replacement, $archives, 1);
echo $archives;

Leave a Comment