Home / loop / Display published posts between two dates
  • How to Display published posts between two dates

    display-published-posts-between-two-dates

    Adding this snippet to your wordpress theme will enable you to display published posts between two dates. You could place this great little snippet within your sidebar or create a custom template to display last years posts.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    <?php
      function filter_where($where = '') {
            $where .= " AND post_date >= '1980-05-11' AND post_date <= '2011-05-11'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    query_posts($query_string);
    while (have_posts()) :
          the_post();
          the_content();
    endwhile;
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, posts_where, query, query_string, have_posts, the_post, add_filter, query_posts,
  • Anouk

    Is it possible to use variables as dates?