WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a plugin and have a problem,

this code gives my all months that post were added:

        <select name="sdate" id="sdate">
    <?php wp_get_archives('format=option'); ?>

the problem is that i dont get dates that only pages were added.

basicaly, i want dropdown thats gonna list every year+month (for example "September 2010") that something was added with value like "year-month" (for example "2010-05")

Something that you can see working on Wordpress Export page, but copied code is not working for me.

share|improve this question
Sounds like wp_get_archives only works for posts, but not pages! – jnthnclrk Nov 24 '10 at 11:47
I would love to know how to get wp_get_archives to work for pages. – jnthnclrk Nov 24 '10 at 12:22

The wp_get_archives() function runs a filter on its WHERE clause--it's called getarchives_where. You could use this to modify the query to only include pages rather than posts (which is the hard-coded default).

I haven't tested this yet, but try it out:


function my_archives_filter($where_clause) {

  return "WHERE post_type = 'page' AND post_status = 'publish'";


Then, just use the wp_get_archives function the way you normally would.

Obviously, this will affect the wp_get_archives function sitewide, so if you use wp_get_archives for grabbing a post archive somewhere else on your site, you'll have to wrap the add_filter in something that recognizes the context.

share|improve this answer
thanks!!! when function is empty, it does what i needed – maniu Nov 25 '10 at 15:19

So, here is code that make it all work(display archive dropdown list with dates that anything has been added):


    function my_archives_filter($where_clause='') {
        return "";

        <select name="sdate" id="sdate">
               <?php wp_get_archives('format=option'); ?>

Thanks MathSmath!

share|improve this answer

Your Answer


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.