-1

I'm trying to use a filter that limits the days ago loops pull posts from.

My problem is that I need different day limits for certain loops on the index page and when I duplicate the filter over a second loop, I get an error saying "Cannot redeclare filter_where() (previously declared in ".)

I remove the filter after the first loop that I use it, but that doesn't help. Here are the filters...

<?php
  function filter_where($where = '') {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
    return $where;
  }
add_filter('posts_where', 'filter_where');
query_posts($query_string);
?>

1 Answer 1

1

Define the filter_where function in your functions.php file in your theme.

<?php
function filter_where($where = '') { 
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; 
    return $where; 
} 
2
  • Hmm ok so how do I change the day limit for different loops in the same page once I do that? Feb 3, 2012 at 0:41
  • 1
    Ok so I just duplicated the function and named it different variations. That's how I was supposed to do it I hope. Feb 3, 2012 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.