Forums

[resolved] Exclude posts by year (3 posts)

  1. chen
    Member
    Posted 1 month ago #

    Hi,

    does anyone know how to exclude old posts by year (ex. in 2004 and 2005) from displaying on the homepage?

    Thank you.

  2. MichaelH
    moderator
    Posted 1 month ago #

    To exclude posts, using the WordPress Default theme for example, in the wp-content/themes/default/index.php file, just before the line:
    <?php if (have_posts()) : ?>

    put this:

    <?php
      function filter_where($where = '') {
        //retrieve posts dated Jan 1, 2006 and newer
        $where .= " AND post_date >= '2006-01-01'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    query_posts($query_string);
    ?>

    The query_posts() article explains the arguments in detail.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  3. chen
    Member
    Posted 1 month ago #

    Hi Michael,

    thank you so much!!!! it works! :)

    thanks again really..

    more power!

Reply

You must log in to post.

About this Topic