• gbengston

    (@gbengston)


    I was wondering if someone can help me with this. I am running multiple loops on a client’s news page and they came back to me saying that they want the loops to only show the past 2 years of posts with the rest being viewable via the archive links.

    This is one of the loops on the news page:

    <!-- Start the Loop for News. -->
    <h3>Corporate News</h3>
    <?php $my_query = new WP_Query('category_name=corporate&posts_per_page=5');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    <br />
    <div class="morenews"><a href="<?php bloginfo('home'); ?>/news/corporate/">More from Corporate »</a></div>
    <!-- End the Loop for Corporate News. -->

    As you can see, I’m using “WP_Query” in the loop, and calling the category via “Category_Name”. Can someone please show me how to turn what I have into a loop that will limit the posts to ones posted in the past 2 years? Any help would be greatly appreciated.

    Thanks in advance,
    Greg

Viewing 2 replies - 1 through 2 (of 2 total)
  • Jonas Grumby

    (@ss_minnow)

    Thread Starter gbengston

    (@gbengston)

    Yeah, I saw that but I couldn’t get it to work.

    I’m assuming you’re referring to this:

    <?php
    //based on Austin Matzko's code from wp-hackers email list
      function filter_where($where = '') {
        //posts in the last 30 days
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    query_posts($query_string);
    ?>

    Any idea on how to combine what I have with the Matzko example?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do you show category posts ONLY from last 2 years?’ is closed to new replies.