Home WordPress General Functions wp_get_archives() WordPress wp_get_archives() Function Definition In WordPress, wp_get_archives() prints a list of archive links , such as one link for each month that has posts. It is the function behind the Archives widget.
You choose the list with the type argument: monthly (default), yearly, daily, weekly, postbypost, or alpha. Each row is built with get_archives_link() .
Syntax Call it inside a list, or pass an array of arguments.
<ul>
<?php
wp_get_archives( array(
'type' => 'monthly',
'limit' => 6,
) );
?>
</ul> Call What it does wp_get_archives()Prints monthly archive links. wp_get_archives( 'type=yearly' )Prints yearly archive links. wp_get_archives( array( 'format' => 'option' ) )Prints option tags for a dropdown.
The default html format prints <li> items, so wrap it in a <ul>.
Full declaration wp_get_archives( string|array $args = '' ): void|string Parameters Parameter Description $argsstring|array. Options: type, limit, format (html, option, link, custom), before, after, show_post_count, echo, order, post_type. Default is an empty string.
Return Value Return Value Description void When echo is 1 (default), the list is printed. string When echo is 0, the list is returned as a string.
WordPress Examples Three short theme examples. Each one shows the code and what it prints.
1. Monthly archives 2. Yearly archives with post counts 3. A dropdown of months Example 1 — Monthly archives List the last three months.
<ul>
<?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 3 ) ); ?>
</ul> <ul>
<li><a href='https://example.com/2026/11/'>November 2026</a></li>
<li><a href='https://example.com/2026/10/'>October 2026</a></li>
<li><a href='https://example.com/2026/09/'>September 2026</a></li>
</ul> How It Works type is monthly, which is also the default.limit keeps only the latest 3 months.Each row is a list item with a link. Example 2 — Yearly archives with post counts Show how many posts each year has.
<ul>
<?php wp_get_archives( array(
'type' => 'yearly',
'show_post_count' => true,
) ); ?>
</ul> <ul>
<li><a href='https://example.com/2026/'>2026</a> (48)</li>
<li><a href='https://example.com/2025/'>2025</a> (61)</li>
</ul> How It Works yearly gives one link per year.show_post_count adds the number in brackets.The counts come from published posts. Example 3 — A dropdown of months Use the option format in a select box.
<select onchange="document.location.href=this.value;">
<option value="">Select month</option>
<?php wp_get_archives( array(
'type' => 'monthly',
'format' => 'option',
'limit' => 3,
) ); ?>
</select> <select onchange="document.location.href=this.value;">
<option value="">Select month</option>
<option value='https://example.com/2026/11/'> November 2026 </option>
<option value='https://example.com/2026/10/'> October 2026 </option>
<option value='https://example.com/2026/09/'> September 2026 </option>
</select> How It Works format is option, so each row is an option tag.The inline script opens the chosen month. The first option is a placeholder. Frequently Asked Questions What does wp_get_archives() do? It prints a list of archive links, such as one for each month or year that has posts.
What types can I use? monthly (default), yearly, daily, weekly, postbypost, and alpha.
How do I return the list instead of printing? Set echo to 0, for example wp_get_archives( array( 'echo' => 0 ) ).
How do I make a dropdown? Use format => option inside a select tag and add a small script to open the chosen link.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
12 people found this page helpful
Helpful Share Copy link Suggestion