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',
    '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;
  • Thanks, I removed the 1st child from the list using css. It really did the trick. May 18, 2018 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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