Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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; 
} 
share|improve this answer
    
Hmm ok so how do I change the day limit for different loops in the same page once I do that? –  Pollux Khafra Feb 3 '12 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. –  Pollux Khafra Feb 3 '12 at 1:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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