• Resolved BAC

    (@bac-1)


    Hi,

    I hope someone might be able to help me.

    I am on 2.9.2 and thematic child theme

    I am trying to filter the main loop, and category loop and search results to only return posts from the last 30 days.

    I think I am close to solving the main loop and category loop issue but it is not working

    I have the following code in my functions.php

    // Filter Index Loop
    function remove_thematic_index_loop() {
          remove_action ('thematic_indexloop','thematic_index_loop');
    }
    add_action('init','remove_thematic_index_loop');
    
    function my_index_loop() {
    
    //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);
    
     while (have_posts()) : the_post(); ?>
    
              <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
                  <?php thematic_postheader(); ?>
                  <div class="entry-content">
    <?php thematic_content(); ?>
    				</div>
                  <?php thematic_postfooter(); ?>
              </div><!-- .post -->
    
          <?php endwhile;
    }
    add_action('thematic_indexloop', 'my_index_loop');

    Does anyone know where I am going wrong here? I tried replacing Austins filter with query_posts('posts_per_page=2'); and this worked.

    Thanks

    BAC

Viewing 1 replies (of 1 total)
  • Thread Starter BAC

    (@bac-1)

    Just in case anyone finds this useful, I solved this by installing the Auto Delete Posts plugin which has the option to move posts over x days to a new category rather than delete the post.

    I could then place the following code just below have_posts in the loop, with 20 being the category ID I want excluded.

    <?php if (in_category(’20’)) continue; ?>
    ie
    while (have_posts()) : the_post(); ?>
    <?php if (in_category(’20’)) continue; ?>

    I also changed Search Unleashed to exclude this category.

    Hope this helps.

    BAC

    http://wordpress.org/extend/plugins/auto-delete-posts/

Viewing 1 replies (of 1 total)
  • The topic ‘Only return posts from last 30 days.’ is closed to new replies.